iOS 返回键盘的实时高度(含三方键盘)
程序员文章站
2022-05-28 22:58:00
...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; #pragma mark -- 键盘显示 -- - (void)keyboardWillShow:(NSNotification *)notification { NSDictionary *info = [notification userInfo]; double duration = [info[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; CGFloat curkeyBoardHeight = [[info objectForKey:@"UIKeyboardBoundsUserInfoKey"] CGRectValue].size.height; CGRect begin = [[info objectForKey:@"UIKeyboardFrameBeginUserInfoKey"] CGRectValue]; CGRect end = [[info objectForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue]; CGFloat keyBoardHeight; /*! 第三方键盘回调三次问题,监听仅执行最后一次 */ if(begin.size.height > 0 && (begin.origin.y - end.origin.y > 0)){ keyBoardHeight = curkeyBoardHeight; [UIView animateWithDuration:duration animations:^{ NSLog(@"键盘高度%f",keyBoardHeight); }]; } }
上一篇: libpng error: Not a PNG file
下一篇: IOS相关参数记录