【发布时间】:2014-06-07 16:32:56
【问题描述】:
我需要将聊天功能添加到即将进行的项目中。
与此同时,我一直在尝试实现我所期望的简单问题,即在屏幕底部有一个 UIView,里面有一个 UITextView,当用户点击 UITextView 时,它将与键盘一起动画.
我有它的工作,但不幸的是,键盘的动画稍微落后于它上面的视图。到目前为止,这是我的实现:
注册键盘通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
键盘通知方式:
- (void)keyboardWillShow:(NSNotification*)notification
{
CGFloat duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
NSInteger curve = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
[UIView animateWithDuration:duration delay:0 options:curve animations:^{
CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
_chatViewBottomConstraint.constant = keyboardFrame.size.height;
[self.view layoutIfNeeded];
} completion:nil];
}
有没有其他人做过类似的,并且能够为我提供更好的解决方案?
【问题讨论】:
标签: ios objective-c uikeyboard