iphone - iOS 6 中 View Controller 的错误旋转

标签 iphone objective-c ios xcode rotation

在我的应用程序中,我一直在使用现已弃用的 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/

相关文章:

ios - 未调用 didDetermineState、didEnterRegion、didExitRegion 事件

ios - 在自定义 TableViewCell 中按下按钮时从 API 打开 URL

iphone - 将关系添加到未保存的NSManagedObject吗?

iphone - 在 iphone 中使用 ASIHTTPRequest

iphone - UIImage 不是编译时常量,Xcode 4

objective-c - 调整 NSWindow 大小时自动调整所有 View 的大小

ios - 在 Swift iOS 的文本字段中添加分隔符 "-"

iPhone - 本地化字符串无法在设备上运行

iphone - 如何只删除一个部分中的行

javascript - 预期的不合格 ID cstdlib