Keeping the contentOffset in a UICollectionView while rotating Interface Orientation

后端 未结 24 1405
野性不改
野性不改 2020-12-04 07:22

I\'m trying to handle interface orientation changes in a UICollectionViewController. What I\'m trying to achieve is, that I want to have the same contentOffset afte

24条回答
  •  感动是毒
    2020-12-04 08:07

    Use and in the method didRotateFromInterfaceOrientation: reload data of the CollectionView.

    Implement collectionView:layout:sizeForItemAtIndexPath: method of and in the method verify the Interface orientation and apply your custom size of each cell.

    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
    {
    
        UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    
        if (UIInterfaceOrientationIsPortrait(orientation)) {
    
            return CGSizeMake(CGFloat width, CGFloat height);
    
        } else {
    
            return CGSizeMake(CGFloat width, CGFloat height);
    
        }
    
    }
    

提交回复
热议问题