-->

Xcode 4.5 SplitView broken orientation with iOS 5.

2019-04-15 04:47发布

问题:

I was working on a splitView project when the Xcode was updated to v4.5. Since then autorotation was working perfectly. After the update, autorotation works only for iOS 6. On iOS 5.1 i am stack in Portrait. I have read all possible solutions but nothing seems to be able to fix my problem. Below is what i have done so far:

Checked that All orientations are in my plist. Replaced (BOOL)shouldAutorotateToInterfaceOrientation: with

- (BOOL)shouldAutorotate
{
    return TRUE;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}

I added the below snippet in the app delegate

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
        return (UIInterfaceOrientationMaskAll);
    }

I show in another answer the below snippet how ever i am not sure how to implement it in a splitView controller

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   ...
   window.rootViewController = topLevelViewController;
   ...
}

Can anybody help me out with this?

回答1:

You need to keep the method from iOS 5:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

to continue support for iOS 5. You thus, keep both the new ones for iOS 6 and the old ones for iOS 5. Note that for the UISplitView to rotate in iOS 5 all the enclosed view controllers have to have the above method.