zoukankan      html  css  js  c++  java
  • 点击空白处以及返回 return 键隐藏键盘

    ///返回键盘处理

    方法1

    此方法只能针对继承自 UIControl的子类适用

    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

        [self.view endEditing:YES];

    }

    方法2

    //添加手势方法监听键盘处理的方法

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

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

        tapGestureRecognizer.cancelsTouchesInView = NO;

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

        [self.view addGestureRecognizer:tapGestureRecognizer];

    //返回键盘处理的方法

    -(void)keyboardHide{

        [self.view endEditing:YES];

    }

    //返回 text return键隐藏键盘

    -(BOOL)textFieldShouldReturn:(UITextField *)textField {

        [self.view endEditing:YES];

            return YES;

    }

    //3.另外一种方法(取消文本的第一响应事件)

    //让键盘隐藏

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

    {

        [_nameTextField resignFirstResponder];

        [_ageTextField resignFirstResponder];

        [_IDTextField resignFirstResponder];

    }

  • 相关阅读:
    [python] defaultdict
    [VM workstation]VM workstation 中的虚拟机连不上网络
    [Docker] docker 基础学习笔记1(共6篇)
    [python] import curses
    servlet 产生随机验证码
    JSTL标签库 sql标签
    JSTLLearning
    Ajax实现联想(建议)功能
    HDU 1241
    Servlet实现文件上传
  • 原文地址:https://www.cnblogs.com/aiyiran/p/5029883.html
Copyright © 2011-2022 走看看