[英]Adjusting UICollectionViewFlowLayout cells on rotation
So I'm working on an app that is part of an ePub framework. 因此,我正在开发属于ePub框架的应用程序。 The app embeds the reader into its view and allows a user to scroll zoom and page by swipe. 该应用程序将阅读器嵌入其视图中,并允许用户通过滑动来滚动缩放和翻页。 Im trying to modify it so that the list of ePubs comes into a collectionview as cells displaying the cover image of the epubs. 我正在尝试对其进行修改,以便将ePub列表作为显示epub封面图像的单元格放入collectionview。 I can create the cells for the flowlayout and using the frame bounds I can create cells but when I try and rotate from portrait to landscape they dont adjust in size and position. 我可以创建用于布局的单元格,并可以使用框架范围创建单元格,但是当我尝试从纵向旋转到横向旋转时,它们的大小和位置都不会调整。 My code for the cells is this: 我的单元格代码是这样的:
//Set Collection View Cell Size and Orientation
-(CGSize)
collectionView:(UICollectionView *) collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
//Set Landscape size of cells
if(UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){
CGFloat cellWidth = [[UIScreen mainScreen] bounds].size.width;
CGFloat cellHeigt = [[UIScreen mainScreen] bounds].size.height-350;
NSLog(@"Is Landscape");
return CGSizeMake(cellWidth, cellHeigt);
}
//Set Potrait size of cells
else{
NSLog(@"Is Portrait");
CGFloat cellWidth = [[UIScreen mainScreen] bounds].size.width-80;
CGFloat cellHeigt = [[UIScreen mainScreen] bounds].size.height-240;
return CGSizeMake(cellWidth, cellHeigt);
}
}
and I use this code to position them: 我使用以下代码来定位它们:
//Collection View Cell Position
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
if(UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)){
return UIEdgeInsetsMake(0,10,0,20); // top, left, bottom, right
}
else{
return UIEdgeInsetsMake(0,20,0,20); // top, left, bottom, right
}
}
When I rotate the device the cells top boundary goes over the frame. 当我旋转设备时,单元格的顶部边界越过框架。
Please help, how can I update the frame dynamically? 请帮助,如何动态更新框架?
You need to refresh collection while rotation . 您需要在轮换时刷新集合。 try following code : 尝试以下代码:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[yourCollectionview performBatchUpdates:nil completion:nil];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.