Я работаю над проектом с UIViewController, на контроллере представления есть UIScrollView и UITextField в scrollview. как это: Я пытаюсь убрать клавиатуру и скрыть ее, набрав текст в текстовом поле и коснуться любого места вне текстового поля. Я пробовал следующий код:
override func viewDidLoad() {
super.viewDidLoad()
self.textField.delegate = self;
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
}
Он работает для меня, когда я выхожу за пределы scrollview, но когда я нажимаю на прокрутку, ничего не происходит, и клавиатура не скрывается.
Есть ли способ отклонить клавиатуру при нажатии в любом месте вне текстового поля? спасибо