【问题标题】:IOS 6 view rotation issue [duplicate]IOS 6视图旋转问题[重复]
【发布时间】:2012-11-04 19:38:29
【问题描述】:

可能重复:
Autorotate in iOS 6 has strange behaviour

我在使用 IOS 6 时遇到问题,显示器显示为纵向而不是横向。 我同时使用真实设备和模拟器设备,如果我在 5.1 模拟器上构建游戏,如果我使用模拟器版本 6 或带有版本 6 的真实设备,则视图会正确呈现,视图是纵向视图。 这是我的代码。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
       interfaceOrientation == UIInterfaceOrientationLandscapeRight )
        return YES;

知道如何解决这个问题吗?

谢谢 呃

【问题讨论】:

  • 哦,拜托,Apple 的文档和发行说明中已经对此进行了广泛的介绍,并且 Stack Overflow 上关于 iOS 6 中新的自动旋转行为有数千个问题。
  • shouldAutorotateToInterfaceOrientation 在 iOS 6 中已弃用。查看 UIViewController 文档..

标签: iphone ios ios6


【解决方案1】:

ShouldAutoRotation 不再适用于 iOS 6。请改用supportedInterfaceOrientations。

您可以在这里获取更多信息:http://dhilipsiva.blogspot.com/2012/07/ios-6-ui-interface-orientation.html

希望这会有所帮助。

【讨论】:

  • 在应用新方法时我仍然遇到同样的问题。
【解决方案2】:

iOS 6 已弃用 shouldAutorotateToInterfaceOrientation 方法。它已替换为以下内容:

- (BOOL)shouldAutoRotate {

    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {

    return UIInterfaceOrientationMaskLandscape;
}

此外,还有一个非常重要的细节来完成这项工作。在您的 AppDelegate 中,确保更改以下内容:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [self.window setRootViewController:<your main view controller here>];
}

如果您使用的是[self.window addSubview:self.mainViewController.view],它将不起作用。

【讨论】:

  • 还是有同样的问题,我应用了以下:
  • - (BOOL)shouldAutorotate { return YES; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ return UIInterfaceOrientationLandscapeLeft; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeLeft; }
  • 等一下,我知道我以前遇到过这个问题。让我看看我做了什么。
【解决方案3】:

如果您想同时支持 iOS 5 和 iOS 6,请将 shouldAutorotateToInterfaceOrientation 留在您的代码中;只知道它不会在 iOS6 设备上调用。

@Simon 给出的示例应该能够与您的原始代码和平共处,任一操作系统调用其适用的方法。我能够在我的应用程序中实现类似的功能,但我使用项目设置为 iOS 6 设置自动旋转,只留下我的 shouldAutorotateToInterfaceOrientation 以使应用程序也与 iOS 5 兼容。

【讨论】:

  • 谢谢西蒙给我的例子并没有真正起作用我仍然有问题视图仍然是纵向视图而不是横向视图你提到你使用项目设置,你是否参考 info.plist 设置.. . 它对我也不起作用..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-15
  • 1970-01-01
  • 2016-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多