xcode - UIPageViewController - 第一次旋转会将 View 重置为初始页面?

标签 xcode ios6 uipageviewcontroller

我试图了解 Apple 的基于页面的应用程序的默认模板。该模板显示了一种日历,一年中的每个月都有一页。

在没有任何更改的情况下编译模板时,我注意到一些奇怪的事情。当应用程序启动时,它以纵向模式显示,并且当 - 在翻阅某些页面(例如,到六月)后 - 您更改旋转时,它会以横向模式重新加载,显示两个页面,但从一月开始。不过,这只会发生一次。在随后的方向更改时,它会跳转到正确的“currentViewController”。

这个代码似乎来自 RootViewController 文件,特别是

UIViewController *currentViewController = self.pageViewController.viewControllers[0];

坦率地说,第一次方向变化似乎被忽略了。

我试图理解为什么?

最佳答案

在将应用程序更新为对 iPhone 5 友好时,我不得不处理同样的问题。使用iOS 6 sdk 编译时,问题出现在iOS 6 上,但在iOS 5 上没有。只有从横向进入PageViewController 时才会发生。

解决方法:

在 .m 的 @interface 部分创建一个属性以保存当前状态:

@property (strong, nonatomic) NSArray *viewControllersSave;

将 viewControllers 保存在 willRotateToInterfaceOrientation :
(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;
}

这可能是避免问题的一种可能性,但您应该向 Apple 提交错误报告,以避免以后使用这种变通方法。

关于xcode - UIPageViewController - 第一次旋转会将 View 重置为初始页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14188592/

相关文章:

iphone - 在 Xcode 中搜索

iphone - 导航栏动画变白

youtube - 在 iOS6 应用程序中嵌入 Youtube 视频在 Safari 中打开视频

ios - iOS6 中的 MapView 在北纬 > 75 时不会显示某些缩放级别

iphone - pageviewcontroller 中的 PageCurlEffect 与工具栏重叠

iphone - IOS 核心动画对象未释放

ios - 设置后设置 View Controller 时以编程方式添加的页面控件消失

iphone Mail App Popup 样式 alertview

iOS - scrollView 和 setContentSize

ios - 重写不在 super 中的方法