use*_*524 3 xcode uipageviewcontroller ios6
我试图了解Apple的基于页面的应用程序的默认模板.该模板显示了一种日历,每年的每个月都有一页.
在没有任何更改的情况下编译模板时,我注意到一些奇怪的东西 当应用程序启动时,它以纵向模式显示,并且 - 在翻阅某些页面(例如,到6月)后 - 您更改旋转,它以横向模式重新加载显示两个页面,但是从1月开始.但这只发生一次.在随后的方向更改中,它然后跳转到正确的"currentViewController".
这个代码似乎来自RootViewController文件,具体来说
UIViewController *currentViewController = self.pageViewController.viewControllers[0];
Run Code Online (Sandbox Code Playgroud)
坦率地说,第一次定位改变似乎被忽略了.
我想知道为什么?
在将App更新为iPhone 5友好时,我不得不处理同样的问题.使用iOS 6 sdk进行编译时,问题会出现在iOS 6上,但不会出现在iOS 5上.只有从横向进入PageViewController时才会出现问题.
解决方法:
创建一个属性以将当前状态保存在.m的@interface部分中:
@property (strong, nonatomic) NSArray *viewControllersSave;
Run Code Online (Sandbox Code Playgroud)
将viewControllers保存在willRotateToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
// some code here...
self.viewControllersSave = self.pageViewController.viewControllers;
}
Run Code Online (Sandbox Code Playgroud)
使用保存的属性而不是PageViewController属性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;
}
Run Code Online (Sandbox Code Playgroud)
这可能是一种避免问题的可能性,但是您应该向Apple提交错误报告,以避免以后使用这种解决方法.
| 归档时间: |
|
| 查看次数: |
2503 次 |
| 最近记录: |