• 键盘回收的几种方法


    用弹出键盘和收回键盘举例子

    第一种

    AppDelegate.h声明协议 UITextFieldDelegate

    AppDelegate.m

    UITextField *t1 = [[UITextField alloc]initWithFrame:CGRectMake(50, 50, 200, 40)];

        t1.borderStyle = UITextBorderStyleRoundedRect;

        t1.backgroundColor = [UIColor yellowColor];

        [self.window addSubview:t1];

       

        // 设置代理,才能执行代理

        t1.delegate = self;

       

    // 点击键盘上的return键

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

      // 解除第一响应者,键盘回收

     

        [textField resignFirstResponder];

     

        return YES;

    }   

       第二种

    //这里加了一个touchesBegan事件。点击屏幕任意处收回键盘

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

    {

        [self.view endEditing:YES];

    }

     第三种 

    //修改xib中UIView的Custom class为UIControl,UIControl是一些常用控件如UIButton的父类,是UIView的派生类,实现了对触摸和下按的封装。

    1、首先设置xib中得UIView的Custom class为UIControl

    2、设置关系事件,将xib中得UIView拖到.h区中

    3、编写隐藏代码:

    - (IBAction)touchView:(id)sender {  

         [self.view endEditing:YES];  

    }  

  • 相关阅读:
    ES6
    JavaScript小练习2
    JavaScript实现多重继承
    一个定高,一个高度自适应的布局
    实例教程:1小时学会Python(转)
    备份文件的python脚本(转)
    Python2.5/2.6实用教程:基础篇(转)
    Python 读写 Excel(转)
    python实用技巧 : Filtering os.walk(转)
    Python:文件操作技巧(File operation)(转)
  • 原文地址:https://www.cnblogs.com/Coder-GT/p/4866323.html
Copyright © 2020-2023  润新知