2016-01-07 点击任何地方的 键盘隐藏

  1. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

    {

        [super touchesBegan:touches withEvent:event];

        [self.view endEditing:YES];

        //隐藏键盘

        [_descrViewa resignFirstResponder];

        

        

        //    [self.editingTextField  resignFirstResponder] ;

        

    }

  2. 第二种方式
  3.  

        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];

        //设置成NO表示当前控件响应后会传播到其他控件上,默认为YES

        tapGestureRecognizer.cancelsTouchesInView = NO;

        //将触摸事件添加到当前view

        [self.view addGestureRecognizer:tapGestureRecognizer];

  4. //隐藏键盘

    -(void)keyboardHide:(UITapGestureRecognizer*)tap{

        [_nameField resignFirstResponder];

    }

posted @ 2016-01-07 13:19  zhen_zhen  阅读(129)  评论(0编辑  收藏  举报