![](/img/trans.png)
[英]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.