首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >旋转调节UICollectionViewFlowLayout细胞

旋转调节UICollectionViewFlowLayout细胞
EN

Stack Overflow用户
提问于 2016-11-03 04:24:35
回答 1查看 190关注 0票数 0

因此,我正在开发一个应用程序,它是ePub框架的一部分。该应用程序将阅读器嵌入其视图中,并允许用户通过滑动滚动、缩放和页面。我试图修改它,以便epubs列表以单元格的形式进入集合视图,显示ePubs的封面图像。我可以为流布局创建单元格,使用框架边界,我可以创建单元格,但是当我尝试从纵向旋转到景观时,它们在大小和位置上都不会调整。我的单元格代码是:

代码语言:javascript
复制
//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);
}
}

我用这个代码来定位它们:

代码语言:javascript
复制
//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
 }
}

当我旋转设备时,单元格顶部的边界会越过帧。

请帮助,我怎样才能动态更新帧?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-03 05:19:23

旋转时需要刷新集合。尝试使用以下代码:

代码语言:javascript
复制
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    [yourCollectionview performBatchUpdates:nil completion:nil];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40393850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档