I have a subclass of UICollectionViewLayout
which places cells in a circle. The
layout returns YES
for the call shouldInvalidateLayoutForBoundsChange:
. On
rotation, the cell in the initial position fades out and the cell in the final
position fades in.
By adding the following code to my layout I can disabled the fades and the circle of items appears to to simply rotate with the orientation change:
- (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath {
return nil;
}
- (UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath {
return [self layoutAttributesForItemAtIndexPath:itemIndexPath];
}
Why do the methods get called on a bounds change because documentation doesn't seem to suggest they do? Documentation seems to state they get called related to insertion and removal of items from the collection view.
Is there a better way to disable the cross fade during rotation?
Notes:
- The
initialLayoutAttributesForAppearingItemAtIndexPath:
documentation states that by default the method returnsnil
but calls tosuper
returned non-nil values. - I set symbolic breaks points on the UICollectionView methods
deleteItemsAtIndexPaths:
,moveItemAtIndexPath:toIndexPath:
andinsertItemsAtIndexPaths:
and none of them are hit during rotation.
The
UICollectionViewLayout.h
file stateswhich clearly says they are called on bounds changes. Rather than removal/insertion, "old state" and "new state" seems more accurate.