Cannot rotate interface orientation to portrait upside down
Asked Answered
S

3

6

Both on iPhone simulator and iPhone 3GS (iOS 6) I cannot manage to set the orientation to portrait upside down. I have just one ViewController. I've added this code in 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've also checked the plist file, both orientations are present there. On my storyboard, at Simulated Metrics Orientation is set to Inferred. I do nothing in my applicationDidFinishLaunchingWithOptions, except return YES. I've just added a UIImageView inside of this ViewController. Is it possible to make this orientation work?

Sprage answered 27/12, 2012 at 16:23 Comment(1)
supportedInterfaceOrientationsForWindow: supposed to return UIInterfaceOrientationMask.Spry
W
11

supportedInterfaceOrientations returns an NSUInteger. It returns all of the interface orientations that the view controller supports, a mask of interface orientation values.

You need to return values defined in UIInterfaceOrientationMask Enum, like the following shows:

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
Wits answered 27/12, 2012 at 16:38 Comment(3)
Thank you so much! At first I thought that I did exactly the same thing, but then I noticed the right name)Sprage
I had to set it in the info section of the target to make it fully work.Cammiecammy
Now there's a combined UIInterfaceOrientationMaskAllCanberra
U
1

I know there's an answer that worked but for anyone else who's still stuck with the same issue:

I had a similar problem that was connected to Xcode: portrait rotations weren't being supported despite returning YES to - (BOOL) shouldAutorotateToInterfaceOrientation: for all cases. It turned out to be the enabled 'Supported Interface Orientations' in the summary window of my target's project editor:

enter image description here

The above 'iPhone/iPad Depoloyment Info' selections weren't doing it, it was the 'iPad Deployment Info' section that appears to control what the simulator will do despite the fact that I was only using the iPhone sim. Once I'd enabled the same orientations in that section then the iPhone simulation worked and I was able to test what happened when the simulator was rotated....

Unthinking answered 17/4, 2013 at 10:33 Comment(4)
Is it just me or are the Landscape Left and Landscape Right graphics in XCode incorrect? Landscape Left from Apple documentation (developer.apple.com/library/ios/#documentation/UIKit/Reference/…): UIDeviceOrientationLandscapeLeft = The device is in landscape mode, with the device held upright and the home button on the right side. The graphic for Landscape Left above shows the home button on the left side. Tested this on a device logging orientations and sure enough, Landscape left should have the home button on the right.Kuo
So, UIDeviceOrientationLandscapeLeft and Right are OPPOSITE of UIInterfaceOrientationLandscapeLeft and Right. Compare docs above against docs for UIInterfaceOrientation: developer.apple.com/library/ios/#documentation/UIKit/Reference/….Kuo
Good spot! Could the thinking be that the phobe and the cg interface have different anchor points and so are rotated relative to different origins...? But why!?Unthinking
@Unthinking the thinking is more like the user interface rotation has to counteract on the device rotation. If the user interface would rotate to the left when you rotate the device to the left, you would end up looking at a user interface that is upside down. 90 degrees rotation of the device plus 90 degrees rotation of the user interface equals 180 degrees (upside down from where you started). To counteract the 90 degree device rotation you have to do -90 degrees on the user interface. This way what was up before the rotation would still be up after the rotation as 90+(-90) = 0.Boisvert
F
0

I tried many ways for this. It seems only one way it works, but globally through the app, not only for particular view controller.

First, you have to check on Upside Down of Device Orientation in target general settings.

check Upside Down of Device Orientation

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

extension UINavigationController {
    override public func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return .All
    }
}
Frontal answered 2/8, 2016 at 6:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.