ios - iOS7 , In CollectionView , When will this method be called? layoutAttributesForElementsInRect: -
i'm new ios developer.
recently i'm learning uicollectionview , i'm trying subclass uicollectionviewlayout.
i have implement method
-(nsarray*)layoutattributesforelementsinrect:(cgrect)rect
question
i have no idea did rect come from? , in scenario rect passed me ?
ps. think method might more easy understand
- (uicollectionviewlayoutattributes *)layoutattributesforitematindexpath:(nsindexpath *)path
because indexpath limited , finite , configure cell in particular indexpath reasonable.
but rect might infinite , have no idea rect came from.
when creating layout subclass must override both methods.
the layoutattributesforitematindexpath
tells collection-view layout attributes cell @ specific index-path. must use cells.
the layoutattributesforelementsinrect
gets called system rectangle contains "visual elements" displayed in - cells, supplementary or decoration views. think of part of collection-view that's displayed. tells collection-view attributes contained in rectangle, can create corresponding views.
basically, can layout attribute calculations (frame, transforms, etc.) inside these functions, or can prepare attributes in advance (you can in preparelayout
method) , return correct cached layout attributes.
Comments
Post a Comment