[英]iOS 6 rotation not working
我重写了UINavigationController来实现以下方法:
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
现在,从我的第一个角度来看,我在此处模态呈现此MSNavigationPaneViewController,就像一个Facebook侧滑动选项卡栏控制器。
我需要在此处显示的视图控制器之一才能仅横向显示,而应用程序的其余视图仅纵向显示。
因此,在所有其他View Controller中,我添加了:
-(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中的方向按钮以启用所需的方向,并以supportedInterfaceOrientations方法返回方向。
首先,请确保您已单击Xcode中的方向按钮以启用所需的方向。 然后花几个小时来搜索人们在使用iOS 6时遇到的所有错误和问题。再花几个小时尝试各种技术。
这篇文章包含了一些线索,但是离最终的决定还很遥远。
特别要注意的是,与在每个视图控制器中实现旋转控制相比,现在必须标识“根视图控制器”并在其中集中大多数(但不是全部)旋转控件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.