3

The keyboard shifts a little bit up sometimes, as shown in picture here

Firstly, this issue happens only on iOS11 but not on earlier iOS versions. Secondly, this issue happens with every UITextField instance across the app not only in one specific text field within a specific view controller.

By observing UIKeyboardWillShowNotification, found that the frame of keyboard stored in UIKeyboardFrameEndUserInfoKey is incorrect, to be exact, the height is wrong.

- (void)keyboardWillShow:(NSNotification *)notification {
    NSDictionary *info = [notification userInfo];
    NSString *curveValue = [info objectForKey:UIKeyboardAnimationCurveUserInfoKey];
    CGRect rect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    NSLog(@"keyboard frame: %@", NSStringFromCGRect(rect));
}

We got logs like this when running on iPhone7 (11.1):

keyboard frame {{0, 451}, {375, 216}}
keyboard frame {{0, 292}, {375, 375}}
keyboard frame {{0, 451}, {375, 216}}
keyboard frame {{0, 292}, {375, 375}}
keyboard frame {{0, 292}, {375, 375}}

216 should be the correct height, while 375 is wrong. It is weird that the height of the keyboard happens to be equal to the width of the screen.

Based on the facts i got, i think it is an IOS 11 keyboard issue, because it happens only on iOS 11, and the height of the keyboard is definitely controlled by iOS, however it returns a wrong height for some reason.

However, the tricky thing is that, i extracted a specific view controller containing a textfield from our app and created a separate demo project, everything works fine then. And i didn't found similar issues happened to others by Googling. So i doubt it maybe because of some settings in our app, which causes this iOS11 keyboard height issue.

Have you guys experienced this kind of weird issues before? Or is there anything you guys can think of which maybe the culprit? I have run out of my thoughts on this. Thanks!

Matthew An
  • 89
  • 6
  • See https://stackoverflow.com/questions/15402281/convert-uikeyboardframeenduserinfokey-to-view-or-window-coordinates – rmaddy Dec 03 '17 at 23:30
  • The incorrect height doesn’t change through the frame conversion. That thread is not related to the issue here. @rmaddy – Matthew An Dec 04 '17 at 00:03

1 Answers1

0

Got it sorted. Finally found it is because a UIView category we use in our project.

- (void)setWidth:(CGFloat)width;
- (void)setHeight:(CGFloat)height;
- (void)setSize:(CGFloat)size;
- (void)setXPos:(CGFloat)xPos;
- (void)setYPos:(CGFloat)yPos;
- (void)setXPos:(CGFloat)xPos yPos:(CGFloat)yPos;

From iOS11 somehow these methods become reserved methods and overriding these methods will cause this annoying issue.

Matthew An
  • 89
  • 6