UICollectionViewLayoutをサブクラスでカスタマイズすると様々なレイアウトでセルを並べられる。


参考


実装

まず必要な実装
  1. collectionViewContentSize スクロール領域のサイズ、大体UICollectionViewのサイズ
  2. layoutAttributesForElementsInRect: UICollectionViewLayoutAttributesのArray
  3. layoutAttributesForItemAtIndexPath: UICollectionViewLayoutAttributesのArray
  4. layoutAttributesForSupplementaryViewOfKind:atIndexPath:
  5. layoutAttributesForDecorationViewOfKind:atIndexPath:
  6. shouldInvalidateLayoutForBoundsChange:

UICollectionViewLayoutAttributes

プロパティ

  1. frame
  2. center
  3. size
  4. transform3D
  5. alpha
  6. zIndex
  7. hidden

参照


  • indexPath
  • representedElementCategory
あなたはこの値を使う事ができる。区別するために。
その区別とはレイアウト属性が一つのセルがsupplementary Viewかdecoration Viewかであるか。

typedef enum {
  UICollectionElementCategoryCell,
  UICollectionElementCategorySupplementaryView,
  UICollectionElementCategoryDecorationView
} UICollectionElementCategory;


  • reperesentedElementKind
あなたはこの値を使うことができる。特定の属性と関連した supplementary かdecoration view の特定の
効果を同定するためにである。
もしthe representedElementCategory propertyにUICollectionElementCategoryCellがはいっていたら
この値はnilとなっている。

クラスメソッド

+layoutAttributesForCellWithIndexPath: 
+layoutAttributesForDecorationViewOfKind:withIndexPath:
+ layoutAttributesForSupplementaryViewOfKind:withIndexPath:



用語

+supplementary view ヘッダ、フッタのような使い方のview
  1. DecorationView 見た目の装飾用

主要メソッド

  1. invalidateLayout 更新
  2. prepareLayout レイアウト処理時に呼ばれる

layoutAttributesForElementsInRect:

領域内にあるView達のUICollectionViewLayoutAttributes の配列を返す。
Cell,DecorationView,SupplementaryViewに応じて
クラスメソッド layoutAttributesFor***を使い分けること。
最終更新:2013年01月06日 18:36