2012-09-29 5 views
12

私はUICollectionViewLayoutのサブクラスを持ち、セルを円に配置します。 レイアウトは、shouldInvalidateLayoutForBoundsChange:の場合はYESを返します。 回転に、初期位置にあるセルがフェードアウトし、最終 位置にあるセルがフェードイン。UICollectionView/UICollectionViewLayoutの回転または境界の変更でクロスフェードを無効にする最適な方法は何ですか?

私のレイアウトに次のコードを追加することにより、私はフェードを無効にすることができ、アイテムの 円は、単にに表示されます姿勢の変化に伴って回転:ドキュメントが は、彼らが示唆していないようなので、

- (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath { 
    return nil; 
} 

- (UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath { 
    return [self layoutAttributesForItemAtIndexPath:itemIndexPath]; 
} 

はなぜな方法は、境界の変化に呼ばれるのですか?ドキュメントには、コレクションビューからのアイテムの挿入と削除に関連する という名前が付けられているようです。

ローテーション中にクロスフェードを無効にするより良い方法はありますか?

注:

  • initialLayoutAttributesForAppearingItemAtIndexPath:ドキュメント は、デフォルトではメソッドがnilを返しますがsuperには 非nilの値を返さ呼び出すと述べています。
  • 私はUICollectionView方法 deleteItemsAtIndexPaths:moveItemAtIndexPath:toIndexPath:insertItemsAtIndexPaths:にシンボリックブレイクポイントを設定し、それらのどれもが回転中にヒットされていません。
+0

これは暗闇の中の単なるショットですが、回転アニメーションを無効にするために、回転操作のために完全にコアアニメーションを停止することができます:[CATransaction begin]; [CATransaction setValue:(id)kCFBooleanFalse forKey:kCATransactionDisableActions]; //あなたの回転を行います [CATransaction commit]; – maz

+0

おそらく、内部的に境界の変更が行われ、項目が削除されて追加され、その結果メソッドが呼び出されることがあります。理由については、-deleteItemsAtIndexPaths:と-insertItemsAtIndexPaths:は呼び出されません..ここでのヒントはありません。おそらく、UIKitのプログラマーは、挿入と削除を実行するためにAPIを不正行為し、避けたのでしょうか?前例がない。 – maz

+1

ここで説明するように、ビューのバッキングレイヤーで暗黙のアニメーションを無効にできますか?http://stackoverflow.com/questions/2244147/disabling-implicit-animations-in-calayer-setneedsdisplayinrect/2244734#2244734? –

答えて

10

UICollectionViewLayout.hファイルの状態はっきりそれらが境界の変更に呼ばれていると言う

// This set of methods is called when the collection view undergoes an 
    animated transition such as a batch update block or an animated 
    bounds change. 
// For each element on screen before the invalidation, 
    finalLayoutAttributesForDisappearingXXX will be called and an 
    animation setup from what is on screen to those final attributes. 
// For each element on screen after the invalidation, 
    initialLayoutAttributesForAppearingXXX will be called an an 
    animation setup from those initial attributes to what ends up on 
    screen. 

。削除/挿入ではなく、「古い状態」と「新しい状態」がより正確に見えます。

関連する問題