UICollectionViewDataSource
,UICollectionViewDelegate
,UICollectionViewDelegateFlowLayout
这三个协议。// 行间距,也可以通过collectionView: layout:minimumLineSpacingForSectionAtIndex:
@property (nonatomic) CGFloat minimumLineSpacing;
// 设置cell之间的间距
@property (nonatomic) CGFloat minimumInteritemSpacing;
// 定义每一个item的大小。通过设定itemSize可以全局地改变所有cell的尺寸,如果想要对某个cell制定尺寸,
//可以使用-collectionView:layout:sizeForItemAtIndexPath:方法。
@property (nonatomic) CGSize itemSize;
@property (nonatomic) CGSize estimatedItemSize
// 滚动方向,默认是水平
// UICollectionViewScrollDirectionVertical
// UICollectionViewScrollDirectionHorizontal
@property (nonatomic) UICollectionViewScrollDirection scrollDirection;
// 根据滚动方向不同,header和footer的高和宽中只有一个会起作用。
// 垂直滚动时section间宽度为该尺寸的高,而水平滚动时为宽度起作用,
@property (nonatomic) CGSize headerReferenceSize;
@property (nonatomic) CGSize footerReferenceSize;
// 组间距 缩进
@property (nonatomic) UIEdgeInsets sectionInset;
// 设定指定Cell的尺寸
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;
// 设定collectionView(指定区)的边距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;
// 设定指定区内Cell的最小行距,也可以直接设置UICollectionViewFlowLayout的minimumLineSpacing属性
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
// 设定指定区内Cell的最小间距,也可以直接设置UICollectionViewFlowLayout的minimumInteritemSpacing属性
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section;
// 边框
@property (nonatomic) CGRect frame
// 中心点
@property (nonatomic) CGPoint center
// 大小
@property (nonatomic) CGSize size
// 形状
@property (nonatomic) CATransform3D transform3D
// 透明度
@property (nonatomic) CGFloat alpha
// 层次关系
@property (nonatomic) NSInteger zIndex
// 是否隐藏
@property (nonatomic, getter=isHidden) BOOL hidden
// 返回collectionView的内容的尺寸
-(CGSize)collectionViewContentSize
// 返回rect中的所有的元素的布局属性
/*
返回的是包含UICollectionViewLayoutAttributes的NSArray
UICollectionViewLayoutAttributes可以是cell,追加视图或装饰
视图的信息,通过不同的UICollectionViewLayoutAttributes初始
化方法可以得到不同类型的UICollectionViewLayoutAttributes:
*/
-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
// 返回对应于indexPath的位置的cell的布局属性
-(UICollectionViewLayoutAttributes _)layoutAttributesForItemAtIndexPath:(NSIndexPath _)indexPath
//返回对应于indexPath的位置的追加视图的布局属性,如果没有追加视图可不重载
-(UICollectionViewLayoutAttributes _)layoutAttributesForSupplementaryViewOfKind:(NSString _)kind atIndexPath:(NSIndexPath *)indexPath
// 返回对应于indexPath的位置的装饰视图的布局属性,如果没有装饰视图可不重载
-(UICollectionViewLayoutAttributes * )layoutAttributesForDecorationViewOfKind:(NSString_)decorationViewKind atIndexPath:(NSIndexPath _)indexPath
// 当边界发生改变时,是否应该刷新布局。如果YES则在边界变化(一般是scroll到其他地方)时,将重新计算需要的布局信息。
-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
// 当指定indexPath处的item被选择时触发
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath;
// 下面是三个和高亮有关的方法:
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath
/*
事件的处理顺序如下:
1.手指按下
2.shouldHighlightItemAtIndexPath (如果返回YES则向下执行,否则执行到这里为止)
3.didHighlightItemAtIndexPath (高亮)
4.手指松开
5.didUnhighlightItemAtIndexPath (取消高亮)
6.shouldSelectItemAtIndexPath (如果返回YES则向下执行,否则执行到这里为止)
7.didSelectItemAtIndexPath (执行选择事件)
*/