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.
}
セルはランドスケープで正しくレンダリングされます。
フロー レイアウトは古いセル サイズを認識しているように見えますが (高すぎるため、問題が発生します)、新しいセル サイズ セットを読み取り/レンダリングしますdidRotateFromInterfaceOrientation
。
苦情を取り除く方法はありますか?
デバイスの回転遷移中に、(現在の画面サイズに対して) 正しいターゲット画面サイズにアクセスできる別のフックを見つけようとしましたが、うまくいきませんでした。デバッグ出力は、苦情が のwillRotateToInterfaceOrientation
前後に発生したことを示していdidRotateFromInterfaceOrientation
ます。
また、明らかなことを確認しました。セルの高さを横長の画面の高さよりも小さい固定サイズに設定すると、苦情は発生しません。また、横向きから縦向きに戻すときも苦情は発生しません。
すべてが正常に実行され、正しくレンダリングされます。しかし、この苦情は私たちを心配させます。他にアイデアや解決策はありますか?