iOS 8 Landscape orientation: Keyboard does not dis

2020-05-23 06:52发布

I have an application compiled for iOS8. The app is set to allow portrait orientation only in the project settings. The views of the application do not rotate to landscape by design. In iOS7 when you rotate the device to landscape the keyboard is not rotated. This is the behaviour I desire.

However, in iOS8 when you rotate the device to landscape the keyboard will incorrectly switch to landscape orientation.

I have tested this on a physical iPhone 6 Plus to confirm the issue. Also tested it on iPhone 5 via simulator. Any idea how to fix this issue?

POTENTIAL FIX

I don't remember exactly why I was doing it but I have some bootstrapping code that executes when the app starts:

    d.window.rootViewController = tabBarController;

Where tabBarController is the top level tab bar controller for the app. Removing this bootstrapping code fixes the issue.

enter image description here

SUGGESTED DEBUGGING

Whilst this did not appear in previous versions of iOS it looks like iOS8 behaves a bit differently. I would recommend checking any bootstrapping code you have. You may have to try a sample project and add some bits until you find the culprit as it was quite hard to track down in my case. The two answers provided below are kind of fixing the symptoms not the cause so I have not marked them as correct.

5条回答
一夜七次
2楼-- · 2020-05-23 07:17

I was facing the same problem mentioned by Carles Estevadeordal on iOS 8 device for the application developed for iOS 7.

After little investigation I found that application was calling following method of UIViewController,

"+ (void)attemptRotationToDeviceOrientation"

Description of this method given in UI framework is, “if the current interface orientation does not match the current device orientation, a rotation may occur”

Simply commenting this method call,the issue got resolved.

查看更多
一纸荒年 Trace。
3楼-- · 2020-05-23 07:19

My problem similar to the question, I tied Emmo213 solution but the error seems to go randomly off and on, so this does not work, the problem in my case seems only to affect the iPhone 6 Plus. I decided to let the response since it may help somebody, if I find one i will edit the response.

iPhone 6 Plus Keyboard disappearing and wrongly placed randomly


Edit: Found a solution, the problem definitely does not happen when the App is not working in scaled mode: How do I create launch images for iPhone 6 / 6 Plus Landscape Only Apps?


Edit: This is definitely not a solution since the problem goes on and off randomly.

I tried Emmo213 solution to the problem and it kind of fixed the problem for me, yet afterwards I deleted this part of code and could not reproduce the problem again...

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                            duration:(NSTimeInterval)duration {
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
        UIDeviceOrientation deviceOrientation;
        switch (toInterfaceOrientation) {
            case UIInterfaceOrientationLandscapeLeft:
                deviceOrientation=UIDeviceOrientationLandscapeRight;
                break;
            case UIInterfaceOrientationLandscapeRight:
                deviceOrientation=UIDeviceOrientationLandscapeLeft;
                break;
            case UIInterfaceOrientationPortrait:
                deviceOrientation=UIDeviceOrientationPortrait;
                break;
            case UIInterfaceOrientationPortraitUpsideDown:
                deviceOrientation=UIDeviceOrientationPortraitUpsideDown;
                break;
            default: deviceOrientation=UIDeviceOrientationUnknown;
                break;
        }
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:deviceOrientation] forKey:@"orientation"];
    }
}

I hope it may help somebody, but since it looks like a rare buggy behaviour difficult to reproduce I cannot assure this is a valid solution...

查看更多
放我归山
4楼-- · 2020-05-23 07:26

It is is not a bug of iOS8 or iPhone 6. It is problem of the correct migration of old projects to xCode6.

You simply need to add Launch screen interface file base name key to Info.plist file.

Detailed explanation of this case you can find here.

查看更多
姐就是有狂的资本
5楼-- · 2020-05-23 07:38

I have a similar problem and have found that pre iOS8 the keyboard orientation is tied to the orientation of the status bar but unfortunately in iOS8 the keyboard and status bar orientation are separate. While it doesn't help solve your problem hopefully this provides a little bit of information as to why it's happening.

Edit: Try the following code - it worked for me. Based on which orientations are allowed you'll have to change which way you're flipping the device obviously.

// Note that UIInterfaceOrientationLandscapeLeft is equal to UIDeviceOrientationLandscapeRight (and vice versa).
// This is because rotating the device to the left requires rotating the content to the right.
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
查看更多
\"骚年 ilove
6楼-- · 2020-05-23 07:44

It is basically the Bug in Xcode 6, to avoid this you may build your project using Xcode 5 or Using Xcode 7. I tried on xcode5 and xcode7-beta and on both versions the keyboard problem was not there. But when i build using xcode 6 then the problem appears , so try to build your project using Xcode 5 or Xcode7 (Soon stable version of Xcode7 will available.). Hope this will help.

查看更多
登录 后发表回答