我試圖在UICollectionViewController中處理接口方向更改。我試圖實現的是,我想要在接口旋轉後有相同的 contentOffset。意思是說,它應該根據邊界變化的比例來改變。在旋轉接口方向時保持UICollectionView中的contentOffset
在縱向與內容的偏移開始{bounds.size.width * 2,0} ...
...應該產生的內容的景觀{邊界偏移也。 size.width * 2,0}(反之亦然)。
計算新的偏移量是沒有問題的,但不知道在哪裏(或者)來設置它,以獲得平滑的動畫。我在做什麼這樣的票價在willRotateToInterfaceOrientation:duration:
無效的佈局和重置內容didRotateFromInterfaceOrientation:
偏移:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration;
{
self.scrollPositionBeforeRotation = CGPointMake(self.collectionView.contentOffset.x/self.collectionView.contentSize.width,
self.collectionView.contentOffset.y/self.collectionView.contentSize.height);
[self.collectionView.collectionViewLayout invalidateLayout];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
{
CGPoint newContentOffset = CGPointMake(self.scrollPositionBeforeRotation.x * self.collectionView.contentSize.width,
self.scrollPositionBeforeRotation.y * self.collectionView.contentSize.height);
[self.collectionView newContentOffset animated:YES];
}
這改變了內容的旋轉後偏移。
如何在旋轉過程中設置它?我嘗試在willAnimateRotationToInterfaceOrientation:duration:
中設置新的內容偏移量,但這會導致非常奇怪的行爲。
一個例子可以在我的項目GitHub中找到。
你找到了一個解決方案? – Ghar