Unable to rotate UI orientation portrait upside down

Both on the iPhone simulator and on the iPhone 3GS (iOS 6), I can’t set the portrait orientation upside down. I have only one ViewController. I added this code to it:

-(BOOL) shouldAutorotate{ return YES; } -(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{ return UIInterfaceOrientationPortraitUpsideDown; } - (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown; } -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ if (toInterfaceOrientation==UIInterfaceOrientationPortrait || toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) { return YES; } return NO; } 

I also added this to AppDelegate.m:

 -(NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown; } 

I also checked the plist file, both orientations are present there. On my storyboard, the Modeled Orientation Metric is set to Inferred. I am not doing anything in my DidFinishLaunchingWithOptions application, with the exception of returning YES. I just added a UIImageView inside this ViewController. Is this orientation possible?

+5
source share
3 answers

supportedInterfaceOrientations returns NSUInteger . It returns all interface orientations supported by the view controller, a mask of interface orientation values.

You need to return the values ​​defined in the UIInterfaceOrientationMask Enum, as shown below:

 - (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown); } 
+11
source

I know there is an answer that worked, but for those who still stuck to the same problem:

I had a similar problem with Xcode: portrait rotations were not supported, despite returning YES to - (BOOL) shouldAutorotateToInterfaceOrientation: for all cases. It turned on ā€œSupported interface landmarksā€ in the summary window of the target project editor:

enter image description here

The above iPhone / iPad Depoloyment Info options didn’t do this, it was the iPad Deployment Information section, which seems to control what the simulator will do, even though I only used the iPhone sim. As soon as I turned on the same orientations in this section, then the iPhone simulation worked, and I was able to check what happened when the simulator was rotated ....

+1
source

I have tried many ways for this. It seems that it works in only one way, but globally through an application, not only for a specific view controller.

First, you should check the Upside Down of Device Orientation in the target general settings.

check vertical orientation

Then, in the extension of the navigation controller, you override the supportedInterfaceOrientations method

 extension UINavigationController { override public func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { return .All } } 
0
source

All Articles