更新應用程序時,我不得不面對同樣的問題,以使iPhone 5更友好。使用iOS 6 sdk進行編譯時,問題出現在iOS 6上,但不出現在iOS 5上。僅當從橫向進入PageViewController時纔會發生此問題。
一種解決方法:
創建一個屬性來保存您的m的@interface部分的當前狀態:在willRotateToInterfaceOrientation
@property (strong, nonatomic) NSArray *viewControllersSave;
保存viewControllers:
(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
// some code here...
self.viewControllersSave = self.pageViewController.viewControllers;
}
使用保存的屬性而不是spineLocationForInterfaceOrientation
中的PageViewController屬性。
- (UIPageViewControllerSpineLocation)pageViewController: (UIPageViewController *)pageViewController
spineLocationForInterfaceOrientation: (UIInterfaceOrientation)orientation
{
// some code
NSArray *viewControllers = @[self.viewControllersSave[0]];
[self.pageViewController setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:NULL];
return UIPageViewControllerSpineLocationMin;
}
這可能是爲了避免該問題的可能性,但你應該提交給蘋果一個bug報告,以避免這樣的解決辦法以備後用。
有趣!這隻發生在iOS6中。在5.1模擬器中運行時,完全相同的代碼正確執行。我已經設置了一個斷點,並注意到在5.1中,當UIPageviewcontrol第一次加載時,不會執行函數「 - (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation',但是在6.0中是這樣的。 – user1459524
檢查了這一點 http://stackoverflow.com/questions/14132132/uipageviewcontroller-resets-to-first-page-on-rotation – Oscar
謝謝,我已經看到這個線程之前,我張貼,但這是無關的我發佈的內容我認爲。我使用Apple提供的基於默認頁面的模板,沒有任何改變,旋轉錯誤只發生在第一次方向改變(並且只在iOS6中)。它適用於後續的方向更改。 – user1459524