I am facing a strange iOS 8.3 issue which shows a keyboard on a wrong orientation like this (the view controller is in Landscape mode, but the keyboard show up in Portrait mode):
I can trigger this issue by following these steps:
Create 2 UIViewController
subClass: ViewControllerA
and ViewControllerB
in ViewControllerA
implement supportedInterfaceOrientations
and return UIInterfaceOrientationMaskPortrait
in ViewControllerB
implement supportedInterfaceOrientations
and return UIInterfaceOrientationMaskLandscape
Create a UINavigationController
subclass called NavigationController
, implement supportedInterfaceOrientations
and return [self.topViewController supportedInterfaceOrientations]
(I'm doing this because I want to keep the NavigationController and it's rootVC from rotating)
Use the NavigationController
as initial view controller of the app, set ViewControllerA
as the NavigationController
's rootViewContrller
Launch the app, ViewControllerA
will shown up in Portrait. Show a button on ViewControllerA
, press the button will present ViewControllerB
by using presentViewController:animated:completion
ViewControllerB
will show up in Landscape; Show a text field on ViewControllerB
, tap on the text field will trigger the keyboard, but the keyboard is in Portrait mode, just like the image above.
PS. You can download and run the Xcode project on github
This issue seems only appears on iOS 8.3. Am I doing something wrong ? Or maybe this is just another bug of iOS ?
By the way, this issue won't happen if you just show ViewControllerA
directly without a ViewController
. So if this is a bug of iOS, how can I avoid subclassing UINavigationController
but still keep ViewControllerA
which is the rootViewController of a UINavigationController
from rotating.
UPDATE: This bug still appears on iOS 8.4, I fired a bug report and got replies from apple on June 17th 2015, they said it has been addressed in the latest iOS 9 beta.
I've asked a tech support and they said
Our engineers have reviewed your request and have determined that this would be best handled as a bug report.
So seems that it's confirmed a system bug.
And my current solution is adding a ViewControllerC (support both portrait and landscape mode) between ViewControllerA and ViewControllerB: ViewControllerA should present ViewControllerC with animation, after ViewControllerC appeared, present ViewControllerB without animation.
To make the transition looks natural, you can set the same background colour as ViewControllerB to ViewControllerC, or take a screen shot of ViewControllerB and add it to ViewControllerC as a background image.
It's not a perfect solution, for users, they may find out ViewControllerB takes more time to load.
We got around this issue by tricking the device into thinking that it was rotated into a different orientation and then into its intended orientation.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.segmentedControl.selectedSegmentIndex = 0;
if(!self.rotatingForDismissal)
{
[self.tableNumberTextField becomeFirstResponder];
}
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.3"))
{
[[UIDevice currentDevice] setValue:@(UIDeviceOrientationLandscapeLeft) forKey:@"orientation"];
[[UIDevice currentDevice] setValue:@(self.interfaceOrientation) forKey:@"orientation"];
}
}
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