Fixed iOS 8.3 keyboard orientation error

I came across a strange iOS 8.3 problem that shows the keyboard in the wrong orientation (the view controller is in landscape mode, but the keyboard is displayed in portrait mode):

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

I can cause this problem 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 subclass of UINavigationController called NavigationController , implement supportedInterfaceOrientations and return [self.topViewController supportedInterfaceOrientations] (I do this because I want the NavigationController and its rootVC to rotate)

    / li>
  • Use NavigationController as initial application view controller, set ViewControllerA as NavigationController rootViewContrller

  • Launch the application, ViewControllerA will appear in the portrait. Show the ViewControllerA button, click the ViewControllerB button using presentViewController:animated:completion

  • ViewControllerB appears in Landscape; Show the text field on ViewControllerB , click on the text field to ViewControllerB keyboard, but the keyboard is in portrait mode, as shown in the figure above.

PS. You can download and run the Xcode project on github

This issue only appears in iOS 8.3. Am I doing something wrong? Or maybe this is another iOS bug?

By the way, this problem will not happen if you just show ViewControllerA directly without ViewController . So, if this is an iOS error, how can I avoid subclassing the UINavigationController , but keep the ViewControllerA , which is the rootViewController of the UINavigationController from rotating.


UPDATE: this error still appears in iOS 8.4, I published a bug report and received answers from apple on June 17, 2015, they said that it was reviewed in the latest version of iOS 9.

+6
source share
3 answers

We encountered this problem by tricking the device into thinking that it was rotated to a different orientation, and then to the 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"]; } } 
+2
source

I asked for technical support and they said

Our engineers reviewed your request and determined that it would be best processed as an error report.

This seems to confirm the system error.

And my current solution adds a ViewControllerC (supports both portrait and landscape mode) between ViewControllerA and ViewControllerB: ViewControllerA should present ViewControllerC with animation, after ViewControllerC appears, there is ViewControllerB without animation.

To make the transition natural, you can set the same background color as ViewControllerB to ViewControllerC or take a screenshot of ViewControllerB and add it to ViewControllerC as a background image.

This is not an ideal solution, for users they may find that ViewControllerB takes longer to load.

+3
source

I was able to properly configure the keyboard using the following.

 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if (SYSTEM_VERSION_GREATER_THAN(@"7.1") && SYSTEM_VERSION_LESS_THAN(@"9.0")) { UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; [[UIDevice currentDevice] setValue:@(UIDeviceOrientationUnknown) forKey:@"orientation"]; [[UIDevice currentDevice] setValue:@(orientation) forKey:@"orientation"]; } } 

Note that using UIDeviceOrientationUnknown does not cause side effects, such as improper auto-rotation of views.

0
source

Source: https://habr.com/ru/post/985880/


All Articles