当键盘打开时,我有这样的代码来收缩和移动我的控件:
-(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
。此键包含有关系统将执行的所有动画之后键盘大小的信息。你可以在这个答案中阅读更多