Core Image Programming Guide--圖像編程指南
javascript
-(CGSize)collectionViewContentSizehtml
-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBoundsjava
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)path{}//返回每一個cell的佈局屬性ios
-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect //返回全部cell的佈局屬性objective-c
關於自定義UICollectionViewLayout的一點我的理解編程
自定義UICollectionView,主要會用到如下幾個方法:
- (void)prepareLayout; 第一次加載layout、刷新layout、以及- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds;這個方法返回yes時,會調用。這是蘋果官方的說明The collection view calls -prepareLayout once at its first layout as the first message to the layout instance. The collection view calls -prepareLayout again after layout is invalidated and before requerying the layout information. Subclasses should always call super if they override。實現該方法後應該調用[super prepareLayout]保證初始化正確。該方法用來準備一些佈局所須要的信息。該方法和init方法類似,但該方法可能會被調用屢次,因此一些不固定的計算(好比該計算和collectionView的尺寸相關),最好放在這裏,以保證collectionView發生變化時,自定義CollectionView能作出正確的反應。
- (nullable NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect; 該方法用來返回rect範圍內的 cell supplementary 以及 decoration的佈局屬性layoutAttributes(這裏保存着她們的尺寸,位置,indexPath等等),若是你的佈局都在一個屏幕內 活着 沒有複雜的計算,我以爲這裏能夠返回所有的屬性數組,若是涉及到複雜計算,應該進行判斷,返回區域內的屬性數組,有時候爲了方便直接返回了所有的屬性數組,不影響佈局但可能會影響性能(若是你的item一屏幕顯示不完,那麼這個方法會調用屢次,當全部的item都加載完畢後,在滑動collectionView時不會調用該方法的)。
- (nullable UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath; 該方法不是必須實現的,即使你實現了,咱們對collectionView的任何操做,也不會致使系統主動調用該方法。該方法一般用來定製某個IndexPath的item的屬性。固然咱們也能夠重寫這個方法,將佈局時相關的屬性設置放在這裏,在- (nullable NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect 或者 - (void)prepareLayout 中 須要建立用來返回給系統的屬性數組 主動調用這個方法,並添加帶可變數組中去返回給系統。固然咱們也能夠在 - (void)prepareLayout 中 經過[UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:[NSIndexPath indexPathForRow:i inSection:0]] 獲取 每一個indexPath的attributes,在- (void)prepareLayout中設置全部item的屬性。看需求以及我的喜歡。
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds; 用來刷新layout的,當咱們返回yes的時候。若是咱們的需求不須要實時的刷新layout,那麼最好判斷newBounds 和 咱們的collectionView的bounds是否相同,不一樣時返回yes;(例如蘋果官方的lineLayout,由於每次滑動都要放大item,因此這了就直接返回yes)。數組
調試:案例學習app