view适应键盘弹出收回的高度
作者:
发现号ZC | 来源:发表于
2016-07-06 19:24 被阅读66次
这几天老有人问我当调键盘出来的时候view怎么自动适应才能不覆盖住textFiled,看好了
// 键盘弹出通知
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(ketBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];
// 键盘回收通知
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(ketBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];
//键盘出现的时候
- (void)ketBoardWillShow:(NSNotification *)sender{
NSLog(@"%@",sender);
// 获取键盘的Frame
CGRect keyBoardRect = [sender.userInfo[UIKeyboardFrameBeginUserInfoKey]CGRectValue];
//
CGRect frame = self.view.frame;
frame.origin.y = -keyBoardRect.size.height;
self.view.frame = frame;
}
//键盘消失
- (void)ketBoardWillHide:(NSNotification *)sender{
self.view.frame = [UIScreen mainScreen].bounds;
}
//点击事件
- (IBAction)btnAction:(id)sender {
[self.filed resignFirstResponder];
}
ok
本文标题:view适应键盘弹出收回的高度
本文链接:https://www.haomeiwen.com/subject/isikjttx.html
网友评论