键盘后更改 UI 控件高度
Change UI control height after keyboard
我有这段代码可以在键盘打开时缩小和移动我的控件:
-(void)keyboardWillShow:(NSNotification *)notification {
NSValue *value = [notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval interval = 0;
[value getValue:&interval];
CGSize keyboardSize = [[notification.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
[UIView animateWithDuration:interval animations:^{
self.composeBarBottomConstraint.constant = (-1) * keyboardSize.height;
[self.view layoutIfNeeded];
}];
}
这与普通键盘完美搭配,但是当我点击表情符号键盘按钮时,UI 控件位置不在应有的位置(向上偏移)并且跳跃而不是动画 - 让我觉得我从 [notification userInfo]
检索到的值在表情符号键盘上是错误的。
知道这里发生了什么吗?
将 UIKeyboardFrameBeginUserInfoKey
替换为 UIKeyboardFrameEndUserInfoKey
。此键包含有关系统将执行的所有动画之后的键盘大小的信息。您可以在 this answer
中阅读更多内容
我有这段代码可以在键盘打开时缩小和移动我的控件:
-(void)keyboardWillShow:(NSNotification *)notification {
NSValue *value = [notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval interval = 0;
[value getValue:&interval];
CGSize keyboardSize = [[notification.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
[UIView animateWithDuration:interval animations:^{
self.composeBarBottomConstraint.constant = (-1) * keyboardSize.height;
[self.view layoutIfNeeded];
}];
}
这与普通键盘完美搭配,但是当我点击表情符号键盘按钮时,UI 控件位置不在应有的位置(向上偏移)并且跳跃而不是动画 - 让我觉得我从 [notification userInfo]
检索到的值在表情符号键盘上是错误的。
知道这里发生了什么吗?
将 UIKeyboardFrameBeginUserInfoKey
替换为 UIKeyboardFrameEndUserInfoKey
。此键包含有关系统将执行的所有动画之后的键盘大小的信息。您可以在 this answer