I learned how to dismiss keyboard when the return key is clicked, or when user touches outside of textfield.
One way is to delegate a class to manage textfield and write the code:
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES; //I'm not sure whether I choose YES or NO
}
Another way is like following:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if (touchToDismissKeyboard.phase == UITouchPhaseBegan) {
[self.firstTextField resignFirstResponder];
}
}
However, with either of the methods above, I found other interfaces are "enabled", such as segmented control or switch which are on the same view as textfield. In addition, when these enabled interfaces is clicked, the keyboard is still on the screen.
Then, my question are how I can make other interfaces unavailable ("enabled = NO") when keyboard appears, and how I can dismiss keyboard with touch on anywhere out of keyboard or textfield without changing values of other interfaces.