iOS 6中视图控制器的旋转不正确

Dan*_*son 2 iphone xcode objective-c rotation ios

在我的应用程序中,我一直在使用现已弃用的shouldAutoRotateToFace方法.现在,当使用iOS 6模拟器时,我的所有子视图都会在设备处于横向状态时旋转为纵向.有谁知道是什么原因引起的?我已经尝试使用supportedOrientations方法替换我的主视图控制器中的autorotate(或者你现在应该使用的任何东西).

Nat*_*ate 7

如果您可以登录Apple dev论坛,请查看此主题.

基本上,这是帮助我的信息:


1.我必须设置window.rootViewController = mainViewController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Run Code Online (Sandbox Code Playgroud)

2.对于视图控制器在哪里

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
Run Code Online (Sandbox Code Playgroud)

只是返回YES,我不得不添加

- (NSUInteger)supportedInterfaceOrientations
Run Code Online (Sandbox Code Playgroud)

返回相同的值

3.补充说

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
            UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}
Run Code Online (Sandbox Code Playgroud)

到mainViewController.m

4.补充说

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
            UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}
Run Code Online (Sandbox Code Playgroud)

到appDelegate.m(我相信这是可选的,用于设置默认值,以防它们未在应用程序的Info.plist文件中指定,或在单个视图控制器中指定)



由于我希望我的代码向后兼容回3.0,我没有使用All orientation mask,因为我需要使用XCode 4.3进行编译

  • "我必须在应用程序的委托中设置window.rootViewController = mainViewController"是为我做的. (2认同)