[英]Modifying a UICollectionViewFlowLayout to change cells positions
[英]Adjusting UICollectionViewFlowLayout cells on rotation
因此,我正在开发属于ePub框架的应用程序。 该应用程序将阅读器嵌入其视图中,并允许用户通过滑动来滚动缩放和翻页。 我正在尝试对其进行修改,以便将ePub列表作为显示epub封面图像的单元格放入collectionview。 我可以创建用于布局的单元格,并可以使用框架范围创建单元格,但是当我尝试从纵向旋转到横向旋转时,它们的大小和位置都不会调整。 我的单元格代码是这样的:
//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);
}
}
我使用以下代码来定位它们:
//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
}
}
当我旋转设备时,单元格的顶部边界越过框架。
请帮助,如何动态更新框架?
您需要在轮换时刷新集合。 尝试以下代码:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[yourCollectionview performBatchUpdates:nil completion:nil];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.