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
相关文章
相关标签/搜索