iOS ViewController点击空白处收起键盘

来源:互联网 发布:云计算平台架构图 编辑:程序博客网 时间:2024/06/06 09:30

点击ViewController空白处时收起键盘,可以通过系统的touchesBegan方法实现,具体如下:

Objective-C 版

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {    [self.view endEditing:YES];}

Swift 版

// 收起键盘override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {    self.view.endEditing(true)}
0 0
原创粉丝点击