码迷,mamicode.com
首页 > 移动开发 > 详细

iOS-三种收起键盘的方法

时间:2015-12-27 10:45:22      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

- (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-三种收起键盘的方法

标签:

原文地址:http://www.cnblogs.com/zhily/p/5079639.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!