參考自:http://www.cnblogs.com/XYQ-208910/p/4985546.html(理論介紹)
參考自:http://www.lxweimin.com/p/0d1e2e067f6c(demo代碼)
集合視圖的自動布局:UICollectionViewLayout是抽象根類,必須用它的子類才能創建實例,下面是重寫的方法,計算item的布局屬性
//每一次重新布局前,都會準備布局(蘋果官方推薦使用該方法進行一些初始化)
-(void)prepareLayout
//重寫layoutAttributesForItemAtIndexPath,返回每一個item的布局屬性(流式布局內部已經幫助完成)
-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
//是否要重新刷新布局(只要顯示的item邊界發生改變就重新布局)
//只要每一次重新布局內部就會調用下面的layoutAttributesForElementsInRect:獲取所有cell(item)的屬性
-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
//返回需要重新布局的所有item的屬性
-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect