I have a viewcontroller with 2 CollectionView Controllers.
I would like on rotation that only one of the collection views resize to a custom size while the other re
I've solved this problem by checking the rotation of the device and then reloading the layout. Checking the screen size and using this size to display my cell.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
//get new width of the screen
screenRect = [[UIScreen mainScreen] bounds];
screenWidth = screenRect.size.width;
//if landscape mode
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
screenDivide = 5;
}
else
{
screenDivide = 3;
}
//reload the collectionview layout after rotating
UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
[layout invalidateLayout];
}
Then I defined the cells like this
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
screenRect = [[UIScreen mainScreen] bounds];
screenWidth = screenRect.size.width;
CGSize elementSize = CGSizeMake(screenWidth/screenDivide, 100);
return elementSize;
}