setAnimationDuration 方法:定义动画的时间。
setAnimationCurve 方法:定义动画的轨迹(动画如何执行)
typedef NS_ENUM(NSInteger, UIViewAnimationCurve) {
UIViewAnimationCurveEaseInOut, // 开始时慢,中间快,结束时慢
UIViewAnimationCurveEaseIn, // 开始慢,然后加速
UIViewAnimationCurveEaseOut, // 逐渐减速
UIViewAnimationCurveLinear // 匀速
};
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardHide:) name:UIKeyboardWillHideNotification object:nil];
-(void)keyboardChangeFrame:(NSNotification*)noti;
{
CGRect rect= [noti.userInfo[UIKeyboardFrameEndUserInfoKey]CGRectValue];
NSLog(@"%@", noti.userInfo);
CGFloat keyboardheight = rect.origin.y;
CGFloat duration=[noti.userInfo[UIKeyboardAnimationDurationUserInfoKey]doubleValue];
CGFloat curve=[noti.userInfo[UIKeyboardAnimationCurveUserInfoKey]doubleValue];
[_messageTable zxp_updateConstraints:^(ZXPAutoLayoutMaker *layout) {
layout.top.offset(0);
layout.left.offset(0);
layout.right.offset(0);
layout.height.offset(keyboardheight-30-80);
}];
[_sendTextView zxp_updateConstraints:^(ZXPAutoLayoutMaker *layout) {
layout.left.offset(0);
layout.right.offset(0);
layout.height.offset(45);
layout.top.equalTo(_messageTable.zxp_bottom).offset(0);
}];
[UIView setAnimationCurve:curve];
[UIView animateWithDuration:duration animations:^{
[self.view layoutIfNeeded];
[self tableScrollToBottom];
} completion:^(BOOL finished) {
}];
}
-(void)keyboardHide:(NSNotification *)noti
{
[self.view endEditing:YES];
[UIView animateWithDuration:0.3 animations:^{
_inputView.frame = CGRectMake(0, ScreenViewWH-260-110, ScreenViewW, 260);
[_inputView mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.offset(0);
make.right.offset(0);
make.bottom.offset(-64);
make.height.offset(260);
}];
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
}];
}
iOS键盘监听方法
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 今天在写键盘弹出和退出时候,利用通知监听事件 偶然发现在使用搜狗第三方键盘时候,有些卡顿。打断点发现: 键盘弹出的...
- 1一般我们出现键盘的时候,都是需要有输入事件,但是如果我们需要监听这个取消键盘, - (BOOL)textFiel...
- 例如一个UIScrollView上有多上输入框,为了避免键盘遮盖整理了一下方法,大家可以借鉴一下。 - (void...
- 监听当键盘将要出现时 OC版 监听当键将要退出时 swift版 OC版 当键盘出现 当键退出 swift版 键盘弹...