IOS: Hide the keyboard
I. // hide the keyboard in the blank space
-(Void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {
[_ FeedBackTextView resignFirstResponder];
[_ TelTextField resignFirstResponder];
}
2. Add a point to hide the keyboard by gesture
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (dismissKeyboard)];
[Self. view addGestureRecognizer: tap];
-(Void) dismissKeyboard {
[Self. userText resignFirstResponder];
[Self. passWordText resignFirstResponder];
}
3. // Add a button above the keyboard to collapse the keyboard
UIToolbar * topView = [[UIToolbar alloc] initWithFrame: CGRectMake (0, 0,320, 30)];
[TopView setBarStyle: UIBarStyleDefault];
// Define two flexibleSpace buttons and place them on the toolBar, so that the completion button will be on the rightmost side.
UIBarButtonItem * button1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target: self action: nil];
UIBarButtonItem * button2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target: self action: nil];
// Define the completion button
UIBarButtonItem * doneButton = [[UIBarButtonItem alloc] initWithTitle: @ "done" style: UIBarButtonItemStyleDone target: self action: @ selector (resignKeyboard)];
// Add these buttons on the toolBar
NSArray * buttonsArray = [NSArray arrayWithObjects: button1, button2, doneButton, nil]; [topView setItems: buttonsArray];
[_ FeedBackTextView setInputAccessoryView: topView];
[_ TelTextField setInputAccessoryView: topView];
// Hide the keyboard
-(Void) resignKeyboard {
[_ FeedBackTextView resignFirstResponder];
[_ TelTextField resignFirstResponder];
}