授权不适用于iOS 6

时间:2012-10-19 15:12:30

标签: ios interface rotation ios6 uiinterfaceorientation

我想我的UIViewController可以自动旋转但只是它,而不是任何其他uiviewcontroller。这个UIViewController被呈现在UINavigationController中,它不能自动旋转。 此代码适用于iOS 5和4,但不适用于iOS6。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return (YES);
}

- (BOOL)shouldAutorotate
{
    return (YES);
}

- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskAll);
}

thx求助:)

2 个答案:

答案 0 :(得分:2)

您需要子类化UINavigationController,在此子类中实现上面的旋转方法。然后,只有当您的可旋转视图控制器可见时,您才能有条件地返回YES / UIInterfaceOrientationMaskAll,如下所示:

shouldAutorotateToInterfaceOrientation:

if ([self.navigationController.visibleViewController isKindOfClass:[MyRotatableViewController class]])
 return (YES);
else
 return (toInterfaceOrientation == UIInterfaceOrientationPortrait);

supportedInterfaceOrientations:

if ([self.navigationController.visibleViewController isKindOfClass:[MyRotatableViewController class]])
 return (UIInterfaceOrientationMaskAll);
else
 return (UIInterfaceOrientationPortrait);

但您必须再次在导航控制器中执行此操作,而不是其子视图控制器。

答案 1 :(得分:0)

iOS 6仅向“最根”视图控制器询问旋转。这必须是你的UINavigationController(实际上是这样的子类,因此你有一个放置旋转委托方法的地方),因为UINavigationController在你的其他控制器之下。还要确保将其设置为窗口的根视图控制器。