键盘事件

Posted 活最好的自己

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了键盘事件相关的知识,希望对你有一定的参考价值。

 1 - (void)buildNotification {
 2     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowWithNotification:) name:UIKeyboardWillShowNotification object:nil];
 3     
 4     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHideWithNotification:) name:UIKeyboardWillHideNotification object:nil];
 5  }
 6 
 7 - (void)keyboardWillShowWithNotification:(NSNotification *)notification {
 8     CGRect rect = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
 9     CGFloat height = rect.size.height - (kDevice_iPhoneX ? kFloatBottomDangerHeight : 0);
10 
11     [UIView animateWithDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue] animations:^{
12         _inputTextView.transform = CGAffineTransformMakeTranslation(0, - height);
13     }];
14 }
15 
16 - (void)keyboardWillHideWithNotification:(NSNotification *)notification {
17     [UIView animateWithDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue] animations:^{
18         _inputTextView.transform = CGAffineTransformIdentity;
19     }];
20 }

 

以上是关于键盘事件的主要内容,如果未能解决你的问题,请参考以下文章

软输入键盘隐藏编辑文本

pyHook无法监听键盘事件?

键盘事件

在片段替换上显示/隐藏 Android 软键盘

Android 事件分发事件分发源码分析 ( Activity 中各层级的事件传递 | Activity -> PhoneWindow -> DecorView -> ViewGroup )(代码片段

打开键盘隐藏片段下方的工具栏