iOS-UICollectionViewLayout方法介紹

注意:UICollectionView的自定義功能就是本身去實現UICollectionViewLayout的子類,而後重寫相應的方法來實現Cell的佈局數組

1.當佈局首次被加載時會調用prepareLayout函數函數

-(void)prepareLayout;

2.自定義ContentSize該方法會返回CollectionView的大小,這個方法也是自定義佈局中必須實現的方法佈局

-(CGSize)collectionViewContentSize; 

3.該方法返回一個數組,該數組中存放的是爲每一個Cell綁定的UICollectionViewLayoutAttributes屬性atom

-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect;

4.該方法中去定製每一個Cell的屬性spa

-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath;

5.該方法就是根據indexPath來獲取Cell所綁定的layoutAtrributes, 而後去更改UICollectionViewLayoutAttributes對象的一些屬性並返回code

-(UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath;

6.該方法是爲Header View或者FooterView來定製其對應的UICollectionViewLayoutAttributesorm

-(UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString*)elementKind atIndexPath:(NSIndexPath *)indexPath;

UICollectionViewLayoutAttributes經常使用的屬性:對象

@property (nonatomic) CGRect frame;
@property (nonatomic) CGPoint center;
@property (nonatomic) CGSize size;
@property (nonatomic) CATransform3D transform3D;
@property (nonatomic) CGRect bounds NS_AVAILABLE_IOS(7_0);
@property (nonatomic) CGAffineTransform transform NS_AVAILABLE_IOS(7_0);
@property (nonatomic) CGFloat alpha;
@property (nonatomic) NSInteger zIndex; // default is 0
@property (nonatomic, getter=isHidden) BOOL hidden; // As an optimization, UICollectionView might not create a view for items whose hidden attribute is YES
相關文章
相關標籤/搜索