FirstResponderから辞任してキーボードを隠すことができない理由はわかりますか?UITextFieldからFirstResponderをresignすることができません
FYI:Xcodeの9
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var label: UILabel!
@IBOutlet weak var text: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
self.text.delegate = self
let tap = UITapGestureRecognizer(target: self, action: #selector(ViewController.tapFunction))
label.isUserInteractionEnabled = true
label.addGestureRecognizer(tap)
}
var keyboardInputEnabled = true
@objc func tapFunction(sender:UITapGestureRecognizer) {
if self.keyboardInputEnabled {
self.text.becomeFirstResponder()
}else{
self.view.endEditing(true)
self.text.resignFirstResponder()
}
self.keyboardInputEnabled = !self.keyboardInputEnabled
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
return self.keyboardInputEnabled
}
func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
return self.keyboardInputEnabled
}
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
return self.keyboardInputEnabled
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
ありがとうございました。私は質問を更新します –