我们使用 UICollectionView 来显示覆盖全屏的单元格(减去状态和导航栏)。单元格大小设置为self.collectionView.bounds.size
:
- (void)viewWillAppear:(BOOL)animated
{
//
// value isn't correct with the top bars until here
//
CGSize tmpSize = self.collectionView.bounds.size;
_currentCellSize = CGSizeMake( (tmpSize.width), (tmpSize.height));
}
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return _currentCellSize;
}
这将为每个设备设置正确的大小。每个单元格都被定义为没有插图,并且布局没有页眉或页脚。但是,当我们从纵向旋转到横向时,我们会得到以下“抱怨”:
the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less that the height of the UICollectionView minus the section insets top and bottom values.
现在我理解了这个错误,但是我们重置了单元格的大小并使用了旋转过渡中内置的流布局:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
//self.collectionView.bounds are still the last size...not the new size here
}
- (void)didRotateFromInterfaceOrientation: UIInterfaceOrientation)fromInterfaceOrientation
{
CGSize tmpSize = self.collectionView.bounds.size;
_currentCellSize = CGSizeMake( (tmpSize.width), (tmpSize.height));
[self.collectionView performBatchUpdates:nil completion:nil];//this will force the redraw/size of the cells.
}
单元格在横向中正确渲染。
似乎 Flow Layout 看到了旧的单元格大小(这会导致抱怨,因为它太高了),但确实读取/渲染了didRotateFromInterfaceOrientation
.
有没有办法摆脱投诉?
我们尝试在设备旋转过渡期间找到另一个挂钩,该挂钩可以访问正确的目标屏幕尺寸(与当前屏幕尺寸相比),但没有成功。调试输出显示投诉发生在 之后willRotateToInterfaceOrientation
但之前didRotateFromInterfaceOrientation
。
我们也验证了显而易见的;如果我们将单元格高度设置为小于横向屏幕高度的固定大小,则不会发生投诉。此外,从横向旋转回纵向时不会发生投诉。
一切运行良好,并且渲染正确。然而,这种抱怨让我们感到担忧。其他人有任何想法或解决方案吗?