我的用户界面结构:
UINavigationController
--UIViewController(first)
|
|Modal
|
V
UINavigationController (subclass)
--UIViewController (contains UIPageViewController)
对于 iOS6 新的自动旋转,我创建了一个 UINavigationController 的子类并添加:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
只想保持方向是纵向。
然后我像这样初始化 UIPageViewController:
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
PageDataViewController *startingViewController = [self viewControllerAtIndex:start storyboard:self.storyboard];
NSArray *viewControllers = [NSArray arrayWithObject:startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL];
self.pageViewController.dataSource = self;
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
// Set the page view controller's bounds using an inset rect so that self's view is visible around the edges of the pages.
CGRect pageViewRect = self.view.bounds;
self.pageViewController.view.frame = pageViewRect;
[self.pageViewController didMoveToParentViewController:self];
然后我执行模态转场, 如果第一个 UIViewController 是纵向的,则 pageViewController 工作, 但是如果第一个 UIViewController 是横向的,我总是会遇到异常:
* Assertion failure in -[UIPageViewController willAnimateRotationToInterfaceOrientation:duration:], /SourceCache/UIKit_Sim/UIKit-2372/UIPageViewController.m:945 Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No view controllers' ** First throw call stack: (0x2a5e012 0x19bae7e 0x2a5de78 0x1450f35 0xd75974 0x9f12b4 0x9f13ea 0x9e4c32 0x9f1372 0x9f13ea 0x9e4c32 0x9f1372 0x9f1751 0x93a1a6 0xbee5f9 0x9ec4f3 0x9ec777 0x9ec7b7 0xd57fe2 0xd49ad9 0xd49b54 0x9b1899 0x9b1b3d 0x13b8e83 0x2a1d376 0x2a1ce06 0x2a04a82 0x2a03f44 0x2a03e1b 0x2c967e3 0x2c96668 0x90265c 0xea7d 0x2685 0x1) libc++abi.dylib: terminate called throwing an exception
最佳答案
其实还有另一种解决方法。
旋转只是调用了rootViewController的willAnimateRotationToInterfaceOrientation方法,你必须实现它的方法。
@interface UIPageViewController (Rotation)
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
@end
//执行文件
#import "UIPageViewController+Rotation.h"
@implementation UIPageViewController(Rotation)
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {}
@end
关于iphone - iOS6 自动旋转 - UIPageViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12568714/