我已经重写了 UINavigationController 来实现这些方法:
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
现在从我的第一个视图中,我以模态方式呈现这个 MSNavigationPaneViewControllerhere https://github.com/monospacecollective/MSNavigationPaneViewController这就像 Facebook 侧滑动标签栏控制器。
我需要此处显示的 1 个视图控制器仅横向显示,而应用程序的其余视图仅纵向显示。
所以在我所有其他视图控制器中我添加了:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate
{
return UIInterfaceOrientationMaskPortrait;
}
在我想要的景观中添加了:
- (BOOL)shouldAutorotate
{
return UIInterfaceOrientationMaskLandscape;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
然而我所有的观点都在旋转。
如果我改变shouldRotate
在这些其他视图上设置为“否”,那么它们会保持纵向,而我想要横向的视图可以旋转,但是我无法让它自行旋转。
另外,一旦旋转,如果我返回到另一个具有shouldRotate = NO;
那么它就无法旋转回纵向。
我已经这样做了几个小时了,但无法让它发挥作用。
Thanks
编辑 - - -
我现在已经完成了这一半工作,并开始了一个新问题来让自动旋转工作here https://stackoverflow.com/questions/13934807/trick-preferredinterfaceorientationforpresentation-to-fire-on-viewcontroller-cha