zoukankan      html  css  js  c++  java
  • 【读书笔记】iOS-开发技巧-三种收起键盘的方法

     

    复制代码
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
        
        UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(10, 100, 200, 200)];
        textField.backgroundColor=[UIColor redColor];
        [self.view addSubview:textField];
        
    }
    
    //第一种收起键盘的方法
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        [self.view endEditing:YES];
    }
    //另外一种收起键盘的方法
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
    }
    //第三种收起键盘的方法
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
    }
    复制代码

     

     

    參考资料: 《iOS开发进阶》 -唐巧

  • 相关阅读:
    ES6 数值类型常用方法
    阿里云如何发布网站
    常用的网站推荐
    笔记一 sql 基础知识
    笔记一 MVC初识
    基础二 面向对象编程
    基础一
    css reset 样式
    CSS 嵌套绝对定位
    ADO
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6896096.html
Copyright © 2011-2022 走看看