如何在IOS6中旋转单个视图控制器

5
如何在iPad中旋转一个单个的ViewController,使用ios6。我已经在appdelegate.m中使用了代理。
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait;
}

现在所有的viewcontroller都是竖屏模式,我希望只有一个viewcontroller能够在横屏模式下使用。

在graphViewController.m文件中。

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

但我无法得到正确的结果,请尽快回复。谢谢。

我认为你应该在你的appDelegate中支持两种方向,并为每个ViewController设置supportedInterfaceOrientations。 - Dave
你在导航控制器中吗? - HpTerm
2个回答

3
请查看此链接 iOS6 发布说明 在 UIKit -> 自动旋转 在 iOS 6 中发生了变化
“更多的责任被移交给应用程序和应用程序委托。现在,iOS 容器(例如 UINavigationController)不会咨询其子视图来确定它们是否应该自动旋转。”
在任何 UIViewController 内部(例如 UINavigationController),shouldAutorotate 方法都不会被调用(在 iOS 6 中)。
如果您使用 UINavigationController,请使用其 shouldAutorotate 方法来确定显示哪个子视图并强制给定方向。

我已经编写了UINavigationController旋转的代码,视图控制器在横向旋转时,但状态栏仍保持为竖屏。 - Manoj Chandola
@ManojChandola 或许你可以在你的问题下方进行编辑,并提供你现在用于旋转的代码,这样我们就可以看一下了。 - HpTerm

0

在你想旋转的 viewController 中使用这个方法,而不是在 app delegate.m 中使用。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

因为在下面的方法中,您正在旋转窗口,所以它会影响整个应用程序。

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait;
}

1
shouldAutorotateToInterfaceOrientation在iOS6中已被弃用,该问题仅适用于iOS6。 - HpTerm
shouldAutorotateToInterfaceOrientation代理在iOS6中已被弃用。 - Manoj Chandola

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接