简体   繁体   中英

iOS 6 autorotation in simulator varies from actual iOS 6 device

My app will not autorotate in the iOS 6 GM simulator but it does with the same version of iOS on the device. Could this be a simulator bug? The app is using deprecated autorotation methods, but they are working fine on the device itself which makes me wonder if the simulator APIs are different?

It should still work with the deprecated rotate methods, but you need to add the following to your didFinishLaunchingWithOptions: method:

self.window.rootViewController = yourRootViewController;

This tells the main window what view controller to send the rotate notifications to. This is new with the iOS 6.0 SDK.

This is what I added to get my app working again:

// Tell the system what we support
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

// Tell the system It should autorotate
- (BOOL) shouldAutorotate {
    return YES;
}

// Tell the system which initial orientation we want to have
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

Adding the following was not enough to make it work on the simulator:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (BOOL) shouldAutorotate {
    return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

To make it work, I also added the following inside the didFinishLaunchingWithOptions function of the appDelegate class:

self.window.rootViewController = viewController;

I stopped getting the following error after this addition: Application windows are expected to have a root view controller at the end of application launch

- (BOOL)shouldAutorotate {
    return NO;
}

and set the supported rotations for the root view controller in the app plist file to only portrait.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM