·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> 【读书笔记】iOS-开发技巧-三种收起键盘的方法

【读书笔记】iOS-开发技巧-三种收起键盘的方法

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

 

复制代码
- (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开发进阶》 -唐巧