UICollectionViewLayoutをサブクラスでカスタマイズすると様々なレイアウトでセルを並べられる。
参考
実装
まず必要な実装
- collectionViewContentSize スクロール領域のサイズ、大体UICollectionViewのサイズ
- layoutAttributesForElementsInRect: UICollectionViewLayoutAttributesのArray
- layoutAttributesForItemAtIndexPath: UICollectionViewLayoutAttributesのArray
- layoutAttributesForSupplementaryViewOfKind:atIndexPath:
- layoutAttributesForDecorationViewOfKind:atIndexPath:
- shouldInvalidateLayoutForBoundsChange:
UICollectionViewLayoutAttributes
プロパティ
- frame
- center
- size
- transform3D
- alpha
- zIndex
- hidden
参照
- indexPath
- representedElementCategory
あなたはこの値を使う事ができる。区別するために。
その区別とはレイアウト属性が一つのセルがsupplementary Viewかdecoration Viewかであるか。
typedef enum {
UICollectionElementCategoryCell,
UICollectionElementCategorySupplementaryView,
UICollectionElementCategoryDecorationView
} UICollectionElementCategory;
あなたはこの値を使うことができる。特定の属性と関連した supplementary かdecoration view の特定の
効果を同定するためにである。
もしthe representedElementCategory propertyにUICollectionElementCategoryCellがはいっていたら
この値はnilとなっている。
クラスメソッド
+layoutAttributesForCellWithIndexPath:
+layoutAttributesForDecorationViewOfKind:withIndexPath:
+ layoutAttributesForSupplementaryViewOfKind:withIndexPath:
用語
+supplementary view ヘッダ、フッタのような使い方のview
- DecorationView 見た目の装飾用
主要メソッド
- invalidateLayout 更新
- prepareLayout レイアウト処理時に呼ばれる
layoutAttributesForElementsInRect:
領域内にあるView達のUICollectionViewLayoutAttributes の配列を返す。
Cell,DecorationView,SupplementaryViewに応じて
クラスメソッド layoutAttributesFor***を使い分けること。
最終更新:2013年01月06日 18:36