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:
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.
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.
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.
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...
- (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..
override var shouldAutorotate: Bool {
if #available(iOS 11.0, *) {
// Anything else iOS 11 specific
return true
}
return false
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With