通常我们键盘回收都遵循 UITextFieldDelegate协议,并且执行方法如下:
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
这样我们首先得设置代理,并且还要遵循协议,在开发过程中带来很大的不便,今天向大家介绍的是UITextField的其他三种键盘回收的方法:
第一种:
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.textField resignFirstResponder];
}
第二种:
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
}
第三种:
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
}
喜欢请收藏,谢谢。