因此,我正在开发一个应用程序,它是ePub框架的一部分。该应用程序将阅读器嵌入其视图中,并允许用户通过滑动滚动、缩放和页面。我试图修改它,以便epubs列表以单元格的形式进入集合视图,显示ePubs的封面图像。我可以为流布局创建单元格,使用框架边界,我可以创建单元格,但是当我尝试从纵向旋转到景观时,它们在大小和位置上都不会调整。我的单元格代码是:
//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
}
}当我旋转设备时,单元格顶部的边界会越过帧。
请帮助,我怎样才能动态更新帧?
发布于 2016-11-03 05:19:23
旋转时需要刷新集合。尝试使用以下代码:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[yourCollectionview performBatchUpdates:nil completion:nil];
}https://stackoverflow.com/questions/40393850
复制相似问题