iOS开发过程中,点击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)
}