一袱蚓、textfield 鍵盤監(jiān)聽
1技潘、textfiled設(shè)置代理
2技扼、設(shè)置監(jiān)聽粮呢,添加通知
-(void)initNotiy{
[[NSNotificationCenterdefaultCenter]addObserver:self
selector:@selector(keyboardWillBeHidden1:)
name:UIKeyboardWillHideNotificationobject:nil];
}
#pragma mark-notif
-(void)keyboardWillBeHidden1:(NSNotification*)aNotification
{[self.viewendEditing:YES];
_addTableView.contentInset=UIEdgeInsetsMake(0,0,0,0);
}
-(void)dealloc{
[[NSNotificationCenterdefaultCenter]removeObserver:self];
}
- (BOOL)textFieldShouldBeginEditing:(UITextField*)textField
{
UIView*view = textField.superview;
while(![viewisKindOfClass:[UITableViewCellclass]]) {
view = [viewsuperview];
}
UITableViewCell*cell = (UITableViewCell*)view;
CGRectrect = [cellconvertRect:cell.frametoView:self.view];
if(rect.origin.y+ rect.size.height>=ScreenHeight-216) {
_addTableView.contentInset=UIEdgeInsetsMake(0,0,216,0);
//移動到底部[self.addTableViewscrollToRowAtIndexPath:[NSIndexPathindexPathForRow:self.listAry.count-1inSection:0]atScrollPosition:UITableViewScrollPositionBottomanimated:NO];}
return YES;
}
鍵盤關(guān)閉
- (BOOL)textFieldShouldReturn:(UITextField*)textField
{
return[textFieldresignFirstResponder];//需要設(shè)置代理
}
二婿失、textView鍵盤監(jiān)聽
1.設(shè)置代理,
2.設(shè)置監(jiān)聽
3.代理方法操作
4.關(guān)閉鍵盤啄寡,這里沒有返回的代理方法豪硅,需要間接的使用另一個方法
-(BOOL)textView:(UITextView*)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text
{
if([textisEqualToString:@"\n"]) {
//換個思路,textview有換行挺物,這里監(jiān)聽這個
[textViewresignFirstResponder];
returnNO;
}
return YES;
}