1、点击Return按扭时收起键盘。注意:需要遵从UITextFieldDelegate协议,并设置好代理
-(BOOL)textFieldShouldReturn:(UITextField*)textField{
return[textField resignFirstResponder];
}
或者
-(BOOL)textFieldShouldReturn:(UITextField*)textField{
return [textField endEditing:YES];
}
或者(这里的View必须是继承于UIControl)
- (BOOL)textFieldShouldReturn:(UITextField*)textField{
return [self.view endEditing:YES];
}
或者
-(BOOL)textFieldShouldReturn:(UITextField*)textField{
return [[[UIApplication sharedApplication]keyWindow]endEditing:YES];
}
2、点击背景View收起键盘
-(void)touchesBegan:(NSSet*)toucheswithEvent:(UIEvent*)event{
//以上4种收起方式中的任何一种
}
网友评论