iOS 返回键盘的实时高度(含三方键盘)
程序员文章站
2022-05-28 21:52:11
...
[[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); }]; } }
上一篇: Qt学习笔记-自绘时钟
下一篇: 如何写一个简单的时钟表盘(qt)