Cell resizing with auto-positioning in iOS 6

Is there a way to resize the cell in UICollectionView

when the device changes from portrait to landscape? With the new iOS 6 layout? I don't want to reload everything UICollectionView

.

Hi guys found a solution in case anyone was wondering. Decision:

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


    if ([indexPath row] == 0 && ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown )){
        return CGSizeMake(768, 400);
    }else if ([indexPath row] == 0 && ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)){
        return CGSizeMake(1024, 400);
    }

return CGSizeMake(255, 200);

      

}

So the sizeForItemAtIndexPath method determines the width and height for each cell using CGSize. All you have to do is determine the orientation of the cell and return the desired height. Keep in mind that I only changed one cell for design purposes.

After that, I named [invalidate layout] in:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

      

which basically gets the layout of each cell again, also it doesn't reload the UICollectionView data!

+3


source to share





All Articles