1

enter image description here

"My View" has a subview (UICollectionView). The subview size is portrait mode 0,0,375,50.

When I launch the app. in landscape following are the results.

Window size in landscape mode is 0,0,375,667.

"My View" resize's in landscape mode, subview also resize's. But the subview size is still 0,0,375,50.

I was expecting subview.bounds to return 0,0,667,50.

The following answer says use bounds , but for me its not working. View resize's but bounds are incorrect.

Reporting incorrect bounds in landscape Mode

Community
  • 1
  • 1
NNikN
  • 3,720
  • 6
  • 44
  • 86

1 Answers1

1

Fixing the constraint and Thank to this answer by Followben you can recalculate base on your view orientation and divide it by your array count

- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(UICollectionViewLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{    
    // Adjust cell size for orientation
    if (UIDeviceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
        return CGSizeMake(170.f, 170.f); //Make sure you calculate This
    }
    return CGSizeMake(192.f, 192.f); //Make sure you calculate This
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    [self.collectionView performBatchUpdates:nil completion:nil];
}
Community
  • 1
  • 1
Brian Nezhad
  • 6,148
  • 9
  • 44
  • 69
  • 1
    Great one, difficult to catch and easy to solve. Layout update was required when orientation changes – NNikN Nov 20 '15 at 03:21
  • Yes, glad we solve this together. Always ping me in the chat room if you have any question, I will help when and if I can. Cheers! – Brian Nezhad Nov 20 '15 at 03:23