窍门preferredInterfaceOrientationForPresentation触发viewController更改

我从这里使用MSNavigationPaneViewController ,并有旋转sorting的工作。 我已经覆盖了我的根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:推动presentViewController: animated:completion:我有旋转工作,所以某些视图可以有不同的方向。 问题是,每个不同方向的视图都需要用户倾斜手机来改变locking在正确方向的方向。 我已经做了大量的阅读,以得到这个工作,似乎我需要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中是如何工作的,而且它已经到了pipe理它的根源。 然而, preferredInterfaceOrientationForPresentation似乎只有在下一个视图presented正确的方法之一时才会被调用。 如果窗户刚被切换,则不行。 所以我确实需要一种方法来欺骗这个被调用。

您可以通过重置其rootViewController来诱骗窗口重新评估其支持的接口方向。

 UIApplication *app = [UIApplication sharedApplication]; UIWindow *window = [[app windows] objectAtIndex:0]; UIViewController *root = window.rootViewController; window.rootViewController = nil; window.rootViewController = root; 

您需要确保执行此代码时,根视图控制器的-supportedInterfaceOrientations将返回适当的蒙版(对应于您要如何强制该方向)。

请注意,这种黑客攻击可能会导致屏幕快速闪烁,并干扰任何正在进行的animation。

preferredInterfaceOrientationForPresentation不会在UINavigationController控制器上调用。

你将不得不UINavigationController ,然后自己实现这个特性。 你只是想委托给topViewController

参考检查: http : //code.shabz.co/post/32051014482/ios-6-supportedorientations-with-uinavigationcontroller

我也发现了一个UINavigationController子类的实现: https : //gist.github.com/3842178