2

我的 iOS 应用程序似乎遇到了困难。

它的部署目标是 iOS5.0,但是我使用的是 iOS 6.0 SDK。

在我的视图控制器中,我有:

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskPortrait;
}

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

这在 iOS5 模拟器中运行时效果很好。视图不会旋转到 LandScape 或倒置。

但是,在 IOS6 模拟器中(以及在设备上),它将继续旋转。

我曾经NSLog检查过-supportedInterfaceOrientations确实被调用了,并且确实调用了两次,但是它仍然旋转到 LandScape (右或左)

我究竟做错了什么?

我还扩展了UINavigationController(我的根视图控制器)以包含以下内容:

@implementation UINavigationController (Rotation_IOS6)

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{    
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

@end

但仍然没有成功。

编辑

根据马特的回答。我还需要使用与我的 UINavigationController 类似的实现来扩展 UITabBarController 并且这很有效。

4

3 回答 3

4

问题可能是您有一个导航界面。你?如果是这样,您需要继承 UINavigationController 并使用该子类的实例作为导航控制器。在那个子类中,就是你实现supportedInterfaceOrientations. 对于任何父视图控制器(例如 UITabBarController)也是如此。

原因是 iOS 6 对旋转的思考方式与 iOS 5完全不同。你认为你从 iOS 5 知道的任何东西都不再适用。在 iOS 6 中,我们从应用程序本身的级别开始,然后通过应用程序委托到根视图控制器或其他全屏视图控制器(例如呈现的视图控制器)并停止。父母不再咨询其子女。

此外,应用程序本身(通过 info.plist 或应用程序委托)必须列出应用程序任何部分可以采用每个方向;视图控制器只能请求其中的一个子集

请参阅发行说明:

http://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html

但是,请注意,这句话是谎言:

为了兼容性,仍然实现 shouldAutorotateToInterfaceOrientation: 方法的视图控制器不会获得新的自动旋转行为

相反,在 iOS 6 中,旧的自动旋转方法被完全忽略了;每个人都会得到新的自转行为。它不是“选择加入”。

于 2012-12-07T02:12:38.650 回答
0

如果您不希望应用程序旋转,您可以从 info.plist 中支持的界面方向中删除横向,并且应该这样做。

否则你需要告诉你的根视图控制器去寻找它的孩子的方向信息。

于 2012-12-07T02:03:01.330 回答
0

检查您的项目设置和 info.plist,它们的优先级高于应用委托。确保只选择了您想要的方向

于 2013-01-09T08:07:24.993 回答