Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8.3 keyboard orientation bug

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):

the view controller is in Landscape mode, but the keyboard show up in Portrait mode

I can trigger this issue by following these steps:

  1. Create 2 UIViewController subClass: ViewControllerA and ViewControllerB

  2. in ViewControllerA implement supportedInterfaceOrientations and return UIInterfaceOrientationMaskPortrait

  3. in ViewControllerB implement supportedInterfaceOrientations and return UIInterfaceOrientationMaskLandscape

  4. 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)

  5. Use the NavigationController as initial view controller of the app, set ViewControllerA as the NavigationController's rootViewContrller

  6. 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

  7. 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.

like image 657
ultragtx Avatar asked Apr 24 '15 12:04

ultragtx


2 Answers

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.

like image 199
ultragtx Avatar answered Sep 22 '22 08:09

ultragtx


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"];
    }

}
like image 37
leokash Avatar answered Sep 23 '22 08:09

leokash