在我的应用程序中,我一直在使用现已弃用的 shouldAutoRotateToFace 方法。现在,当使用 iOS 6 模拟器时,当设备处于横向时,我的所有 subview 都旋转为纵向。有谁知道是什么原因造成的?我已经尝试用 supportedOrientations 方法(或您现在应该使用的任何方法)替换主视图 Controller 中的 should autorotate。
最佳答案
如果您可以登录 Apple 开发论坛,check out this thread .
基本上,这是对我有帮助的信息:
1. 我必须在 window.rootViewController = mainViewController
中设置
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
2. 对于 View Controller ,其中
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
没有只是返回YES
,我不得不添加
- (NSUInteger)supportedInterfaceOrientations
返回相同的值
3.添加
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}
到mainViewController.m
4.添加
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}
到 appDelegate.m(我相信这是可选的,用于设置默认值,以防它们未在应用程序的 Info.plist 文件或单独的 View Controller 中指定)
因为我希望我的代码向后兼容 3.0,所以我没有使用 All 方向掩码,因为我需要使用 XCode 4.3 进行编译
关于iphone - iOS 6 中 View Controller 的错误旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12549234/