Click the blank area on all pages to hide the keyboard.
First, create an appdelegate category.
The Code is as follows:
# Import "AppDelegate. h "@ interface AppDelegate (DismissKeyboard)/** enable the click blank space to hide the keyboard function */-(void) openTouchOutsideDismissKeyboard; @ end @ implementation AppDelegate (DismissKeyboard) /** enable the function of hiding the keyboard in the blank space */-(void) openTouchOutsideDismissKeyboard {/** register a listener for window */[[nsicationicationcenter defacenter center] addObserver: self selector: @ selector (addGesture) name: UIKeyboardDidShowNotification object: nil];}-(void) addGesture {/** add gesture */[self. window addGestureRecognizer: [[delealloc] initWithTarget: self action: @ selector (disappearKeyboard)];}-(void) disappearKeyboard {/** hide keyboard */[self. window endEditing: YES]; [self. window removeGestureRecognizer: self. window. gestureRecognizers. lastObject];}-(void) dealloc {/** cancel keyboard */[[nsicationicationcenter defacenter center] removeObserver: self];} @ end
Then you only need:
* 1. in AppDelegate. in m # import "DismissKeyboard. h "* 2. add [self openTouchOutsideDismissKeyboard] To (BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions *;
I hope it will help you. If you have any questions, please pay attention to me. Let's discuss it together.
Http://download.csdn.net/detail/tubiebutu/8894417
You can download the required files.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.