UIPageViewController - 第一次轮换将视图重置为初始页面? [英] UIPageViewController - first rotation resets views to initial page?

查看:127
本文介绍了UIPageViewController - 第一次轮换将视图重置为初始页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to understand Apple's default template for a Page-based application. That template shows a sort of calendar with one page for each month of the year.

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

When compiling the template without any changes, I noticed something odd. When the app launches, it displays in portrait mode, and when - after flipping through some of the pages (say, to June) - you change the rotation, it reloads in landscape mode showing two pages, BUT STARTING WITH JANUARY. This happens only once, though. On subsequent orientation changes, it then jumps to the correct "currentViewController".

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

The code for this seems to come from the RootViewController file, specifically

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

坦率地说,第一次定位更改似乎被忽略了。

And frankly, it seems to be ignored for the first orientation change.

我想了解原因?

推荐答案

我在更新时必须处理同样的问题一个应用程序是iPhone 5友好。使用iOS 6 sdk进行编译时,问题会出现在iOS 6上,但不会出现在iOS 5上。只有从横向进入PageViewController时才会出现问题。

I had to deal with the same issue when updating an App to be iPhone 5 friendly. When compile with iOS 6 sdk, the problem appear on iOS 6, but not on iOS 5. It happens only when entering the PageViewController from landscape orientation.

解决方法:

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

Create a property to save the current state in @interface section of your .m :

@property (strong, nonatomic) NSArray *viewControllersSave;

将viewControllers保存在 willRotateToInterfaceOrientation

Save the viewControllers in willRotateToInterfaceOrientation :

(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    // some code here...
    self.viewControllersSave = self.pageViewController.viewControllers;
}

使用保存的属性而不是中的PageViewController属性spineLocationForInterfaceOrientation

Use the saved property instead of the PageViewController property in 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避免这种解决方法以供以后使用。

This could be a possibility to avoid the problem BUT you should submit a bug report to Apple to avoid such a workaround for later usage.

这篇关于UIPageViewController - 第一次轮换将视图重置为初始页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆