I am working on an iPad application using AutoLayout, where if the user turns on a certain mode (head-up mode), I want to support only portrait (or portrait upside down) orientation and, moreover, if the device is in landscape, I I would like to automatically switch to portrait mode.
In the top view controller, I have the following:
- (NSUInteger) supportedInterfaceOrientations { if (self.modeHeadsUp) { return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; } else { return UIInterfaceOrientationMaskAll; } } - (BOOL) shouldAutorotate { return TRUE; }
Based on the answers I saw elsewhere here, it seems that I should use "application setStatusBarOrientation". Therefore, in the method in which the user selected the one-on-one mode, I turned on:
UIApplication *application = [UIApplication sharedApplication]; [application setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
However, it just does nothing. Although I can physically move the device so that it rotates into a portrait position, it does not do this automatically.
In fact, when in landscape mode, after running the above code, trying to programmatically set the orientation, when I request the application "statusBarOrientation" with the following code, it remains at "4" for landscape:
UIApplication *application = [UIApplication sharedApplication]; int orientation = [application statusBarOrientation]; self.movesTextView.text = [NSString stringWithFormat:@"ORIENTATION %d", orientation];
It seemed like autolayout might not start using setStatusBarOrientation, so I tried adding this code after, but to no avail:
[super updateViewConstraints]; [self.view updateConstraints];
I understand that Apple wants to leave the orientation of the device in the hands of the user. However, I would like to be able to maintain landscape mode when not in a one-on-one mode.
Am I missing something to make me change my orientation?