您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页iOS中输入框随键盘上下移动

iOS中输入框随键盘上下移动

来源:伴沃教育

1.在初始化方法里边注册键盘坐标移动的通知

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];//监听键盘的坐标的变化

2,实现输入框随键盘移动的方法

-(void)keyboardChangeFrame:(NSNotification*)notification

{

//从通知中取出动画速率

intcurve = [[notification.userInfoobjectForKey:UIKeyboardAnimationCurveUserInfoKey]intValue];

//取出动画时间

floatduration = [[notification.userInfoobjectForKey:UIKeyboardAnimationDurationUserInfoKey]floatValue];

//取出键盘动画结束后键盘的frame

CGRectendFrame = [[notification.userInfoobjectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];

[UIViewanimateWithDuration:durationanimations:^{

[UIViewsetAnimationCurve:curve];

_commentView.frame=CGRectMake(0, endFrame.origin.y-H_i6real(38),self.view.frame.size.width,H_i6real(38));

_commentTableView.frame=CGRectMake(W_i6real(10), endFrame.origin.y-(self.view.frame.size.width/2)-H_i6real(10),self.view.frame.size.width-W_i6real(80+10),self.view.frame.size.width/2-H_i6real(38));

}];

}

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务