UICollectionView
からデバイスを回転させるときのカスタムレイアウト(サブクラス:UICollectionViewLayout
)の不思議な動きがあります。カスタムレイアウトのUICollectionViewインターフェイスローテーション
私は単純に水平にスクロールするセルの行を持っています。デバイスをポートレートからランドスケープに回転させると、以前は表示されなかった追加のセルが表示され、表示されるセルのアニメーションが間違っています(コレクションビューのデフォルトのアニメーションエフェクトレイアウト)。ここまでアニメーションで左に表示されたセルに注意してください:
カスタムレイアウトのセットアップに関するいくつかの詳細:
shouldInvalidateLayoutForBoundsChange:
戻りYES
。layoutAttributesForItemAtIndexPath:
では、属性がまだ作成されていない場合は辞書にキャッシュします。layoutAttributesForElementsInRect:
で、私はどの細胞を手で見るべきかを計算し、それらの属性を返す前に少しずつその性質を微調整します(centre
)。
私は、初期/最終的なレイアウト属性に対処するために、次のコードを持っている:
- (void)prepareForAnimatedBoundsChange:(CGRect)oldBounds
{
[super prepareForAnimatedBoundsChange:oldBounds];
self.animatingBoundsChange = YES;
}
- (void)finalizeAnimatedBoundsChange
{
[super finalizeAnimatedBoundsChange];
self.animatingBoundsChange = NO;
}
- (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
{
if (self.animatingBoundsChange) {
// If the view is rotating, appearing items should animate from their current attributes (specify `nil`).
// Both of these appear to do much the same thing:
//return [self layoutAttributesForItemAtIndexPath:itemIndexPath];
return nil;
}
return [super initialLayoutAttributesForAppearingItemAtIndexPath:itemIndexPath];
}
- (UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
{
if (self.animatingBoundsChange) {
// If the view is rotating, disappearing items should animate to their new attributes.
return [self layoutAttributesForItemAtIndexPath:itemIndexPath];
}
return [super finalLayoutAttributesForDisappearingItemAtIndexPath:itemIndexPath];
}
それ(初期レイアウトが新たに出現したセルの属性は何とか右ではないように私には思えます結局のところ正しい位置にがあります)。しかし、initalLayout...
メソッドから返されたレイアウト属性のcenter
プロパティを記録すると、すべてが正しいように見えます。すべてが水平軸に沿って均等に配置されています。
initialLayout...
メソッドが呼び出されると、正しくアニメーション化されないセルの唯一の特徴は、そのセルが[collectionView visibleCells]
の配列に返されないことです。しかし、その前にあるlayoutAttributesForElementsInRect:
は、そのレイアウト属性が必要であることを正しく認識します。
何が起こっているのですか?フードの下で何が起こっているのかについてのいくつかの洞察はとても役に立ちます... UICollectionView
は大規模なブラックボックスのようです。
http://stackoverflow.com/questions/12649271/what-is-the-best-best-way-to-disable-cross-fades- on-uicollectionview-uicollectio?rq = 1 –
移行がスムーズに行えないことが検出された場合、つまりこのシナリオでは、既存のセルと衝突するすべてのセルでクロスフェードアニメーションが使用されます。これは、iOS7のUICollectionViewsのWWDCビデオに記載されています。 – Tim
@Arun_kその質問はこれに関連するようには見えません。なぜ彼らは 'initial/finalLayout ...なぜ?'は回転中に呼び出され、実際には、上記のようにコードを追加するとクロスフェードアニメーションが__prevents__することが確認されます。この質問は、アニメーション境界の変更に続いて表示される追加のセルに関するものです。 – Stuart