這幾天老有人問我當(dāng)調(diào)鍵盤出來的時(shí)候view怎么自動(dòng)適應(yīng)才能不覆蓋住textFiled,看好了
// 鍵盤彈出通知
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(ketBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];
// 鍵盤回收通知
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(ketBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];
//鍵盤出現(xiàn)的時(shí)候
- (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;
}
//點(diǎn)擊事件
- (IBAction)btnAction:(id)sender {
[self.filed resignFirstResponder];
}
ok
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者