iphone6, ios12.1.4で実機テストしたところキーボードは出てくるのですが、リターン、textField外をタップしてもキーボードが閉じませんでした。解決方法を教えて欲しいです
Swift
1import Foundation 2import UIKit 3 4class AddPinViewController: UIViewController { 5 6 let taskTextField: UITextField = { 7 let tf = UITextField() 8 tf.placeholder = "要件を記入してください。" 9 tf.translatesAutoresizingMaskIntoConstraints = false 10 return tf 11 }() 12 13 override func viewDidLoad() { 14 super.viewDidLoad() 15 16 taskTextField.delegate = self 17 18 view.backgroundColor = .green 19 view.addSubview(taskTextField) 20 21 taskTextField.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true 22 taskTextField.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true 23 } 24 25 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 26 self.view.endEditing(true) 27 } 28} 29 30extension AddPinViewController: UITextFieldDelegate { 31 func textFieldShouldReturn(_ textField: UITextField) -> Bool { 32 textField.resignFirstResponder() 33 return true 34 } 35} 36
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。