点击非输入框时隐藏键盘

- ( BOOL )textFieldShouldBeginEditing:( UITextField *)textField
{
     UITapGestureRecognizer *tapGestureRecognizer = [[ UITapGestureRecognizer alloc ] initWithTarget : self action : @selector (done:)];
     tapGestureRecognizer .numberOfTapsRequired = 1 ;
     [ self .view addGestureRecognizer : tapGestureRecognizer ];   //只需要点击非文字输入区域就会响应hideKeyBoard
     [tapGestureRecognizer release ];
     return YES ;
}
 
-( void )done:( id )sender
{
     for ( UIView *view in self .view .subviews ) {
         if ([view isKindOfClass :[ UITextField class ]]) {
             [view resignFirstResponder ];
         }
     }
}
苹果官方的单例写法多学习苹果官方的例子..
+ (NetworkManager *)sharedInstance
{
    static dispatch_once_t  onceToken;
    static NetworkManager * sSharedInstance;
 
    dispatch_once(&onceToken;, ^{
        sSharedInstance = [[NetworkManager alloc] init];
    });
    return sSharedInstance;
}

你可能感兴趣的:(点击非输入框时隐藏键盘)