When it's the right moment to rotate the layout options of the UICollectionView

Hope a simple question regarding a relatively new UIKit control

I have a UICollectionView that has a viewLayout with one row of cells, which is the exact height of the borders of the UICollectionView in portrait mode

Therefore, when the iPad is turned into landscape mode, this line becomes higher than the screen itself, after which the layout (almost) silently fails and complains that the line is above the borders.

What is the ideal way to manipulate the characteristics of viewLayout, especially when it comes to turning response in the ViewController ?

+8
ios iphone uikit uicollectionview
source share
1 answer

I am working on a similar issue.

Currently, my UICollectionViewController has two instance variables of UICollectionViewFlowLayout, each of which has corresponding inserts for portait or terrain.

When spinning, I do this:

 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ if (UIDeviceOrientationIsPortrait(toInterfaceOrientation)) { [_itemCollection setCollectionViewLayout:_portraitLayout]; [_itemCollection reloadData]; } else { [_itemCollection setCollectionViewLayout:_landscapeLayout]; [_itemCollection reloadData]; } } 

The only problem I am facing is that it randomly crashes from exc_bad_access to setCollectionViewLayout randomly.

Something like the above might work for you. I'm not sure if this is the right way to do something. I just recently started using UICollectionViews.

+3
source share

All Articles