您的位置:首页 > 产品设计 > UI/UE

iOS-UICollectionViewLayout方法简单介绍

2017-05-10 10:33 471 查看
注意:UICollectionView的自定义功能就是自己去实现UICollectionViewLayout的子类,然后重写相应的方法来实现Cell的布局

1.当布局首次被加载时会调用prepareLayout函数

-(void)prepareLayout;


2.自定义ContentSize该方法会返回CollectionView的大小,这个方法也是自定义布局中必须实现的方法

-(CGSize)collectionViewContentSize;


3.该方法返回一个数组,该数组中存放的是为每个Cell绑定的UICollectionViewLayoutAttributes属性

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


4.该方法中去定制每个Cell的属性

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


5.该方法就是根据indexPath来获取Cell所绑定的layoutAtrributes, 然后去更改UICollectionViewLayoutAttributes对象的一些属性并返回(追加视图)

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


6.该方法是为Header View或者FooterView来定制其对应的UICollectionViewLayoutAttributes

-(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


以上来转载来自:http://www.cnblogs.com/WJJ-Dream/p/5830606.html

尊重原创。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息