[英]Nimbus NIPagingScrollView and Re-Layouting on Rotation
我正在使用NIPagingScrollView
在iPhone上顯示多個頁面。
每當我滑動到一頁時,也會預加載下一頁,這很好。
當我將 iPhone從縱向模式旋轉到橫向模式時,我可以使用layoutSubviews
在NIPageView
子類中進行重新布局。 NIPagingScrollView
設置為在寬度和高度上自動拉伸以保持全屏顯示。 這適用於當前頁面。
但是,當我輕拂到下一頁時,布局被破壞了,因為它是之前被預取的,並且還通過自動調用layoutSubviews
進行布局。
我猜原點不會在旋轉的下一頁上更新,或者類似的東西。
有沒有人暗示過我如何避免這個問題(除了不使用“風景”之外)? 這是Nimbus中的錯誤嗎?
編輯:我發現NIPagingScrollView
提供了方法willRotateToInterfaceOrientation:duration:
和willAnimateRotationToInterfaceOrientation:duration:
應當由視圖控制器調用。 我實現了這些調用,但仍然無濟於事。
NIPagingScrollView
確實提供了這些方法,但是如果您看一下它們,就會發現布局計算是基於scrollview幀值的。
因此,如果希望將正確的值提供給頁面滾動視圖,例如,將框架或主視圖(控制器視圖)賦予頁面滾動視圖(本例中為_scrollView)。
這樣,就在動畫之前,分頁滾動視圖將具有正確的等待幀,並且布局將被正確地重新計算。
- (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation
duration: (NSTimeInterval)duration {
// Your missing line of code to set the scroll view frame values
[self->_scrollView setFrame:self.view.bounds];
[self->_scrollView willAnimateRotationToInterfaceOrientation: toInterfaceOrientation
duration: duration];
[super willAnimateRotationToInterfaceOrientation: toInterfaceOrientation
duration: duration];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.