Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionViewDelegateFlowLayout methods not called on rotation

Inside of my Collection View Layout (a subclass of UICollectionViewFlowLayout) I have defined:

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
    return YES;
}

My expectation is that since rotation is a bounds change, my layout will get recalculated. However when I set a breakpoint in:

- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(UICollectionViewLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

The breakpoint is not triggered when the screen rotates. Does anyone know why?

like image 715
Andrew Lauer Barinov Avatar asked Feb 13 '15 19:02

Andrew Lauer Barinov


1 Answers

The collectionView:layout:sizeForItemAtIndexPath: method should be implemented in the class that is the UI CollectionViewDelegate class. Not in the sub class of the UICollectionViewLayout. Where did you implement it?

PS. There is no need to use both. If you have a custom UICollectionViewLayout class, use layoutAttributesForItemAtIndexPath: instead

like image 180
AShavit Avatar answered Oct 18 '22 16:10

AShavit