preferredInterfaceOrientationForPresentation must return a supported interface orientation
Your code should look like this:
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
Also, make sure in your Info.plist
you have set the correct orientations for you app because what you return from supportedInterfaceOrientations
is intersected with the Info.plist
and if it can't find a common one then you'll get that error.
preferredInterfaceOrientationForPresentation must return a supported interface orientation (iOS 6)
In -supportedInterfaceOrientations
, you need to return values from UIInterfaceOrientationMask
, not UIInterfaceOrientation
. In particular, it looks like you want UIInterfaceOrientationMaskPortrait
Here's what the documentation for -supportedInterfaceOrientations says about the return value:
Return Value
A bit mask specifying which orientations are supported. See “UIInterfaceOrientationMask” for valid bit-mask values. The value returned by this method must not be 0.
iOS6 Preferred Interface Orientation Not Working
It would appear Apple have removed the ability to push a view in a specific orientation. preferredInterfaceOrientationForPresentation
does get called, but only when popping back or presenting a view controller. I had to present my landscape view rather than push it, and set shouldAutoRotate
= NO.
Refer to: In iOS6, trouble forcing ViewController to certain interfaceOrientation when pushed on stack for more details.
Error when dismissing a MPmovieViewController in landscape to a view in portrait only (UIApplicationInvalidInterfaceOrientation)
I'm answering myself. In fact it was very simple.
Just add to the portrait only view :
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; }
Thanks
App crashes on closing modal view controller
You are returning the wrong thing. The value it expects is UIInterfaceOrientationPortrait
, but you're returning UIInterfaceOrientationMaskPortrait
. Note the Mask part.
Understanding iOS 6 Interface orientation change
About preferredInterfaceOrientationForPresentation
preferredInterfaceOrientationForPresentation
is never called because this is not a "presented" view controller. There is no "presentation" involved here.
"Presented" and "presentation" are not some vague terms meaning "appears". These are precise, technical terms meaning that this view controller is brought into play with the call presentViewController:animated:completion:
. In other words, this event arrives only if this is what we used to call a "modal" view controller.
Well, your view controller is not a modal view controller; it is not brought into play with presentViewController:animated:completion:
. So there is no "presentation" involved, and therefore preferredInterfaceOrientationForPresentation
is irrelevant here.
I'm being very explicit about this because I'm thinking that many folks will be confused or misled in the same way you were. So perhaps this note will help them.
Launch into Landscape
In iOS 6, the "Supported Interface Orientations" key in your Info.plist is taken much more seriously than previously. The solution to your overall problem of launching into a desired orientation is:
Make sure that "Supported Interface Orientations" in your Info.plist lists all orientations your app will ever be allowed to assume.
Make sure that the desired launch orientation is first within the "Supported Interface Orientations".
That's all there is to it. You should not in fact have to put any code into the root view controller to manage the initial orientation.
Related Topics
How to Get a Nsurl from an Xcassets Bundle
How to Lookup a String Constant at Runtime in Objective-C
Libraries Not Found When Using Cocoapods with iOS Logic Tests
Uitableviewcell Checkmark to Be Toggled on and Off When Tapped
How to Compare Two Nsdate Objects in Objective C
Checking for Multiple Asynchronous Responses from Alamofire and Swift
Linker Error in iOS (Duplicate Symbols for Architecture X86_64)
Amazon Aws iOS Sdk: How to List All File Names in a Folder
How to Access Both Objective-C and Swift Classes from Same Storyboard
Preferredinterfaceorientationforpresentation Must Return a Supported Interface Orientation
Swift 3: Type 'Any' Has No Subscript Members
What Is Prefix.Pch File in Xcode
Mkmapview Mkpointannotation Tap Event
Add Lefthand Margin to Uitextfield
How to Keep a Round Imageview Round Using Auto Layout
The Operation Couldn't Be Completed. (Com.Facebook.Sdk Error 2.) iOS6