UICollectionView自定義布局筆記

自定義布局需要繼承類UICollectionViewLayout,然后重寫該類提供的一些方法:

1、- (void)prepareLayout; 準(zhǔn)備layout,可以初始化一些參數(shù),設(shè)置一些屬性。

2、- (CGSize)collectionViewContentSize;返回collectionView的contentSize。

3、- (NSArray? *)layoutAttributesForElementsInRect:(CGRect)rect; ? 返回rect(可視范圍)內(nèi)所有cell對(duì)應(yīng)的layoutAttribute。

4、 - (UICollectionViewLayoutAttributes)layoutAttributesForItemAtIndexPath:(NSIndexPath)indexPath;返回indexPath對(duì)應(yīng)item的layoutAtture對(duì)象。

5、- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds;當(dāng)collectionView的大小發(fā)生改變時(shí),是否重新刷新layout:

6、 - (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity;當(dāng)collectionView滾動(dòng)停止的時(shí)候停在什么位置。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容