Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best best way to disable cross fades on UICollectionView/UICollectionViewLayout rotates or bounds changes?

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 disable 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 returns nil but calls to super returned non-nil values.
  • I set symbolic breakspoints on the UICollectionView methods deleteItemsAtIndexPaths:, moveItemAtIndexPath:toIndexPath: and insertItemsAtIndexPaths: and none of them are hit during rotation.
like image 529
Evan Avatar asked Sep 29 '12 01:09

Evan


1 Answers

The UICollectionViewLayout.h file states

// 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.

which clearly says they are called on bounds changes. Rather than removal/insertion, "old state" and "new state" seems more accurate.

like image 196
Kalle Avatar answered Sep 20 '22 16:09

Kalle