4

フレームのUICollectionViewがあります

[UIScreen mainScreen].bounds

およびこれらの属性:

_collectionView.pagingEnabled = YES;
_collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

セルには、コレクション ビューのサイズもあります。回転すると、コレクション ビューの contentOffset が新しい向きに収まりません。回転前と同じオフセットのままです。

これを修正するために、didRotate メソッドで contentOffset を手動で変更しました。

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    _collectionView.contentOffset = CGPointMake(_newContentOffsetX, _collectionView.contentOffset.y);
}

これは機能しますが、ひどいようです。また、現在の IndexPath までスクロールしようとしましたが、同じ醜い動作をしています。

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [_collectionView scrollToItemAtIndexPath:_currentIndexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:NO];
}

デバイスを回転させるときに、コレクション ビューのコンテンツ オフセットを更新するクリーンな遷移と動作が必要です。

4

2 に答える 2

-1

を使用する代わりに、didRotateFromInterfaceOrientationで更新contentOffsetしてみてくださいwillRotateToInterfaceOrientation。まだ回転していないため、回転する他の幅/高さの寸法を使用して補正する必要があります。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    _collectionView.contentOffset = CGPointMake(_newContentOffsetX, _collectionView.contentOffset.y);
}
于 2014-04-27T01:50:49.613 に答える