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));

}];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容