简体   繁体   中英

iOS11 keyboard issue - incorrect keyboard height

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM