// I used the UIGesture
First: alloc a TapGestureRecognizer
- (void)textFieldDidBeginEditing:(UITextField *)textField{
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
}
//and remember to set the endEditing to YES
- (void)dismissKeyboard {
//hide the keyboard
[keyTextField becomeFirstResponder];
[self.view endEditing:YES];
}
Second: at the textFieldDidEndEditing, we need to remove the TapGestureRecognizer that we alloc-ed above (don't forget this)
- (void)textFieldDidEndEditing:(UITextField *)textField{
[self.view removeGestureRecognizer:tap];
}
Yep, that's it. So now, to dismiss the UITextField we just need to tap outside and it will go away :D
Thanks for reading and please give me some comments/feedbacks.
Thanh Tran.
PS: Demo will be given later.