4

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

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

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

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

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

我试图理解为什么?

4

1 回答 1

5

在将应用程序更新为对 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.

- (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 提交错误报告以避免这种变通方法供以后使用。

于 2013-01-17T09:09:18.443 回答