码迷,mamicode.com
首页 > 其他好文 > 详细

三种收起键盘的方法

时间:2015-08-11 23:10:46      阅读:129      评论: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];
}

三种收起键盘的方法

标签:

原文地址:http://www.cnblogs.com/wq-gril/p/4722395.html

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