OK Fixed.
Using UINavigationController, when I popToViewController:animated: from a landscape view to a portrait view, the destination view appears correct but the status bar and also the UIKeyboard keeps the landscape configuration, making a real mess.
Working around
After thousands of recommendations about statusBarOrientation and references read...
https://developer.apple.com/library/content/releasenotes/General/RN-iOSSDK-6_0/index.html
"The setStatusBarOrientation:animated: method is not deprecated
outright. It now works only if the supportedInterfaceOrientations
method of the top-most full-screen view controller returns 0. This
makes the caller responsible for ensuring that the status bar
orientation is consistent."
(thanks to Vytis in here)
statusBarOrientation only works if supportedInterfaceOrientations returns 0, so... that give us a guess.
If statusBarOrientation is not as expected, one zero return will do it (if always return 0, the view wont rotate, so:
// if deviceOrientation is A (so I expect statusbarOrientation A
// but statusbarOrientation is B
// return 0
// otherwise
// return user interface orientation for A
- (NSUInteger)supportedInterfaceOrientations {
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
UIInterfaceOrientation statusBarOrientation =[UIApplication sharedApplication].statusBarOrientation;
if(deviceOrientation == UIDeviceOrientationPortrait || deviceOrientation == UIDeviceOrientationPortraitUpsideDown){
if(statusBarOrientation != UIInterfaceOrientationPortrait ||statusBarOrientation != UIInterfaceOrientationPortraitUpsideDown){
return 0;
}
}
// otherwise
return UIInterfaceOrientationMaskPortrait;
}
Now, in viewDidAppear (believe me, I use this call even when the keyboard notification is recived:
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
more than 48 labor hrs in this.
Hope this helps a while, thanks to all.
makeKeyAndVisible
is called a bit later than your code? Myself I've also triedself.interfaceOrientation
to no avail. – MinskcurrentOrientation
property to store the interface orientation of myUIViewController
subclass, and then using the code above to find its value. Changing toself.interfaceOrientation
worked for me. If you're still having trouble, try callingmakeKeyAndVisible
at the start of your app delegate'sdidFinishLaunchingWithOptions:
method and see if it makes a difference. – FeudatorymakeKeyAndVisible
earlier, but it turned out my controller'sviewDidLoad
andawakeFromNib
are always called before delegate'sdidFinishLaunchingWithOptions:
. Anyway, I won't give up :) – Minsk