我正在使用来自这里的MSNavigationPaneViewController
,并且已经实现了旋转的功能。
我在我的根UINavigationController
中重写了旋转方法。
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.topViewController != nil) {
return [appDelegate.topViewController supportedInterfaceOrientations];
} else {
return UIInterfaceOrientationMaskPortrait;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.topViewController != nil) {
return [appDelegate.topViewController preferredInterfaceOrientationForPresentation];
} else {
return UIInterfaceOrientationPortrait;
}
}
我使用presentViewController: animated:completion:
方法推出了MSNavigationPaneViewController
,并且使得某些视图可以具有不同的方向。问题在于:每个具有不同方向的视图需要用户倾斜手机才能改变方向,此时它会锁定正确的方向。
我已经阅读了很多资料以使其工作,并且似乎需要在加载每个视图之前触发preferredInterfaceOrientationForPresentation
,但它没有触发。
我认为它没有触发是因为MSNavigationPaneViewController
没有使用presentViewController
来更改视图控制器。
以下是MSNavigationPaneViewController
用于更改视图的代码:
- (void)setPaneViewController:(UIViewController *)paneViewController
{
if (_paneViewController == nil) {
paneViewController.view.frame = _paneView.bounds;
_paneViewController = paneViewController;
[self addChildViewController:_paneViewController];
[_paneView addSubview:_paneViewController.view];
[_paneViewController didMoveToParentViewController:self];
} else if (_paneViewController != paneViewController) {
paneViewController.view.frame = _paneView.bounds;
[_paneViewController willMoveToParentViewController:nil];
[self addChildViewController:paneViewController];
void(^transitionCompletion)(BOOL finished) = ^(BOOL finished) {
[_paneViewController removeFromParentViewController];
[paneViewController didMoveToParentViewController:self];
_paneViewController = paneViewController;
};
[self transitionFromViewController:_paneViewController
toViewController:paneViewController
duration:0
options:UIViewAnimationOptionTransitionNone
animations:nil
completion:transitionCompletion];
}
}
看起来只是在切换viewController,因此没有调用preferredInterfaceOrientationForPresentation
。有没有办法强制调用preferredInterfaceOrientationForPresentation
,或者通过隐藏视图来欺骗它被调用?
谢谢
编辑 ----
我完全理解iOS6中新的旋转系统是如何工作的,以及它由根管理。但是,只有在使用正确的方法之一“presented”下一个视图时,才会调用preferredInterfaceOrientationForPresentation
。如果仅切换窗口,则不会调用该方法。因此,我确实需要一种方法来欺骗它被调用。