iOS 6旋转不起作用
我已经覆盖了我的UINavigationController来实现这些方法:
-(BOOL)shouldAutorotate { return [[self.viewControllers lastObject] shouldAutorotate]; } -(NSUInteger)supportedInterfaceOrientations { return [[self.viewControllers lastObject] supportedInterfaceOrientations]; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; }
现在从我的第一视图,我模态地呈现这个MSNavigationPaneViewController 在这里就像一个Facebook侧滑标签栏控制器。
我需要在这里显示的我的视图控制器中的一个显示横向,而应用程序的其余视图是仅肖像。
所以在我添加的所有其他视图控制器中:
-(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - (BOOL)shouldAutorotate { return UIInterfaceOrientationMaskPortrait; }
并在我想要的景观,我已经添加:
- (BOOL)shouldAutorotate { return UIInterfaceOrientationMaskLandscape; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; }
然而,我所有的观点旋转。
如果我在这些其他视图上更改了shouldRotate
为NO,那么它们将停留在Portrait中,而我想成为Landscape的视图可以旋转,但是我不能让它自己旋转。 另外,一旦旋转,如果我回到另一个有shouldRotate = NO;
视图shouldRotate = NO;
那么它不能被旋转回肖像。
我已经在这个几个小时了,不能得到它的工作。
谢谢
编辑—–
我有这一半现在工作,并开始了一个新的问题,让自动旋转在这里工作
看起来你混淆了在shouldAutorotate中返回什么。 以下面的代码为例。
由于iOS正响应来自加速度计的事件向您的应用程序的shouldAutorotate调用,因此它已经知道新的方向; 如果您的应用程序回答“是”,则iOS可以根据受支持的列表检查当前的方向,并在没有您的应用程序查询当前方向的情况下提出决定。
// iOS 6
- (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; }
此外,您可以让显示您的模态视图控制器的视图控制器通知它的旋转。 使用:presentViewController:animated:completion:显示视图控制器。 presentModalViewController:animated:已被弃用,如果碰巧你正在使用它。
如果您添加application:supportedInterfaceOrientationsForWindow:
:,请确保遵循下面的代码准则。 该文档指出,如果您在VC上实现supportedInterfaceOrientations
,它应该覆盖应用程序委托。 但是,人们已经注意到,它是如何将rootViewController
添加到主窗口的。
使用:
window.rootViewController = viewController
代替:
[window addSubview:viewController.view];
我这样做了
-(BOOL) shouldAutorotate{ return YES; } -(NSUInteger) supportedInterfaceOrientations{ if ([self.visibleViewController isKindOfClass:[ZoomPictureViewController class]]) { return UIInterfaceOrientationMaskAll; } return UIInterfaceOrientationMaskPortrait; }
确保您已经点击Xcode中的方向button来启用所需的方向,并返回supportedInterfaceOrientations方法中的方向。
首先,确保你已经点击Xcode中的方向button来启用你想要的方向。 然后花几个小时searchiOS 6遇到的所有错误和问题。再花几个小时尝试各种技术。
这篇文章包含了一些线索,但是远不是这个问题的最后一句话。
请特别注意,您现在必须识别“根视图控制器”,并将大部分(但不是全部)旋转控件集中在每个视图控制器中。