我目前有以下用于计算UICollectionViewCells大小的代码段:
- (CGSize)collectionView:(UICollectionView *)mainCollectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)atIndexPath
{
CGSize bounds = mainCollectionView.bounds.size;
bounds.height /= 4;
bounds.width /= 4;
return bounds;
}
Run Code Online (Sandbox Code Playgroud)
这有效.但是,我现在正在添加一个键盘观察器viewDidLoad(它触发了UICollectionView它出现之前的委托和数据源方法,并从故事板中调整自身大小).因此,界限是错误的.我也想支持轮换.如果UICollectionView更改大小,处理这两个边缘情况并重新计算尺寸的好方法是什么?