Nic Hubbard
Nic Hubbard

Reputation: 42173

iOS6 autorotation confusion and support for iOS5

Since iOS6, I realize that the shouldAutorotateToInterfaceOrientation: method has been deprecated. Most of my app I would like the user to be able to rotate, which does work in iOS6 and 5 currently. But, I have a modal view that I ONLY want to be portrait, so I have added the following without it actually working (tested in simulator and device):

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

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

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

Why isn't this code preventing my modal from rotating? How can I still support the iOS5 method as well as the iOS6 methods without crashing for users on iOS5?

Upvotes: 2

Views: 977

Answers (2)

Ahmed Hammad
Ahmed Hammad

Reputation: 445

You missed to but this line inside your -(void)viewDidLoad method

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"UIApplicationSupportedInterfaceOrientationsIsEnabled"];

I hope this can help you

Upvotes: 0

The Zaporozhian
The Zaporozhian

Reputation: 108

You have to embed the presented vc in a navigation controller where you can set the preferred orientation.

https://stackoverflow.com/a/12522119

Upvotes: 3

Related Questions