这几天老有人问我当调键盘出来的时候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