iOS 6轮换无法正常工作

时间:2012-12-17 23:08:51

标签: iphone ios cocoa-touch uiinterfaceorientation

我已经覆盖了我的UINavigationController来实现这些方法:

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

现在从我的第一个视图来看,我模态地呈现了这个MSNavigationPaneViewController here,它就像一个Facebook侧滑动标签栏控制器。

我需要在此处显示的1个视图控制器才能显示横向,而应用程序视图的其余部分仅为纵向。

所以在我所有的其他视图控制器中,我添加了:

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate
{
    return UIInterfaceOrientationMaskPortrait;
}

并且在我想要的景观中我添加了:

- (BOOL)shouldAutorotate
{
    return UIInterfaceOrientationMaskLandscape;
}
-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

然而我的所有观点都在旋转。

如果我在这些其他视图上将shouldRotate更改为NO,那么它们将保留在Portrait中,我想要成为Landscape的视图可以旋转,但是我无法让它自行旋转。 此外,如果我回到另一个有shouldRotate = NO;的视图,那么一旦旋转,它就无法旋转回肖像。

我已经在这里工作了好几个小时,无法让它发挥作用。

由于

编辑-----

我现在正在使用这一半并开始一个新问题以使自动轮换工作here

3 个答案:

答案 0 :(得分:5)

看来你在confAutorotate中回归会让人感到困惑。使用以下代码作为示例。

由于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];

答案 1 :(得分:2)

我是这样做的

-(BOOL) shouldAutorotate{
    return YES;
}

-(NSUInteger) supportedInterfaceOrientations{
    if ([self.visibleViewController isKindOfClass:[ZoomPictureViewController class]]) {
        return UIInterfaceOrientationMaskAll;
    }
    return UIInterfaceOrientationMaskPortrait;
}

确保您已单击Xco​​de中的方向按钮以启用所需的方向,并在supportedInterfaceOrientations方法中返回方向。

答案 2 :(得分:1)

首先,确保您已单击Xco​​de中的方向按钮以启用所需的方向。然后花几个小时谷歌搜索人们在iOS 6中遇到的所有错误和问题。还有几个小时试验各种技术。

This post包含一些线索,但远不是最后的话。

特别注意您现在必须识别"根视图控制器"并将大部分(但不是全部)旋转控制集中在那里,而不是在每个视图控制器中实现它。