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) {
}];
}
网友评论