Incorrect rotation of a view controller in iOS 6

2019-02-11 03:59发布

In my app I've been using the now deprecated shouldAutoRotateToFace method. Now when using the iOS 6 simulator, all of my subviews are rotated to portrait orientation while the device is in landscape. Does anyone have any idea what could cause this? I've already tried replacing should autorotate in my main view controller with the supportedOrientations method (or whatever it is that you're now supposed to use instead).

1条回答
别忘想泡老子
2楼-- · 2019-02-11 04:26

If you can log in to the Apple dev forums, check out this thread.

Basically, this is the information that helped me:


1. I had to set window.rootViewController = mainViewController in

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

2. For view controllers where

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation

didn't just return YES, I had to add

- (NSUInteger)supportedInterfaceOrientations

that returned the same value

3. Added

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
            UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}

to mainViewController.m

4. Added

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

to appDelegate.m (I believe this is optional, for setting default values in case they're not specified in the app's Info.plist file, or in individual view controllers)



Since I want my code backwards compatible back to 3.0 I didn't use the All orientation masks, as I need to compile using XCode 4.3

查看更多
登录 后发表回答