我想实现一个动作,当用户点击屏幕上的某个地方时,键盘应该消失。
当我点击文本字段然后键盘出现,这很好 现在我想,当我点击屏幕上的某个地方时,键盘应该消失 我实现了具有以下属性值的轻敲手势识别器:
点击手势识别器我在视图控制器中绑定了以下操作
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var nameField: UITextField!
@IBOutlet weak var numberField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func textFieldDoneEdition(sender: UITextField) {
sender.resignFirstResponder()
}
@IBAction func onTapGestureRecognized(sender: AnyObject) {
nameField.resignFirstResponder()
numberField.resignFirstResponder()
}
}