Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 11 Device Orientation Autorotation

For iOS 10 and below, the following code controlled the orientation of the any respective UIViewController. I have selected Portrait, Landscape Left, and Landscape Right in my Deployment Info, and have the following in my Info.plist:

enter image description here

For my VC's that should not rotate at all I have the following code, which I stated, was working prior iOS 11

- (BOOL)shouldAutorotate {
    [super shouldAutorotate];
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    [super supportedInterfaceOrientations];
    return UIInterfaceOrientationMaskPortrait;
}

I have tested this on actual devices and as of iOS 11 it does not work.

Even more strangely, logging the registered device orientation as of iOS 11 tells my the device IS portrait... when the controller loads in landscape mode...

Code:

// In viewDidLoad 
NSLog(@"orientation: %lu", [[UIDevice currentDevice] orientation]);

Console output:

2017-09-22 15:20:26.225196-0400 <APP_NAME>[2669:1628408] orientation: 1

This occurs either rotating the device left or right before building and running the app.


  • What is the cause here for this error? If anyone knows please help..

FYI: No, I do not have rotation lock on my device..

like image 277
Will Von Ullrich Avatar asked Sep 22 '17 19:09

Will Von Ullrich


People also ask

How do you turn off auto rotate on iPhone 11?

Swipe down from the top right-hand corner of your screen to open Control Centre. Tap the Portrait Orientation Lock button to make sure it's turned off.

Where is rotation lock in settings?

To check other rotation settings, open the Quick settings panel by swiping down from the top of the screen. Touch and hold the Auto rotate icon to open its settings, and then review the options for the Home screen, Lock screen, and Voice call screen.


Video Answer


1 Answers

Whether this proves to be an iOS 11 bug or not, I seemed to have stumbled upon a "solution" to this issue. For whatever reason, for iOS 11 changing the - (BOOL)shouldAutorotate return to YES allows for the correct orientation...

Objc

- (BOOL)shouldAutorotate {

    [super shouldAutorotate];
    
    if (@available(iOS 11, *)) return YES;
    return NO;

}

In combination I had to do a manual check for the screen dimensions to see if the width was greater or less than the supposed height of the screen.

width = self.view.frame.size.width, height = self.view.frame.size.height;
if (height < width) width = height, height = self.view.frame.size.width;

Hopefully someone else finds the true cause of this "bug" OR Apple updates their bundle to handle rotations like all previous iOS versions..

Swift 3.2+

override var shouldAutorotate: Bool {

    if #available(iOS 11.0, *) {
        // Anything else iOS 11 specific
        return true
    } 
    return false

}
like image 88
Will Von Ullrich Avatar answered Sep 18 '22 23:09

Will Von Ullrich