override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
keyboardUpNotification()
keyboardDownNotification()
}
func keyboardUpNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
print("keyboard up notification registered")
}
func keyboardWillShow(_ notification: Notification) {
view.frame.origin.y = 0 - keyboardSize(notification)
print("keyboard will show method. \(keyboardSize(notification))")
}
func keyboardDownNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
print("keyboard down notification registered")
}
func keyboardWillHide() {
print("keyboard will hide method")
view.frame.origin.y = 0
}
2つの通知(キーボードの上下)を追加します。戻るボタンをタッチすると、キーボードが非表示になります。しかし、keyboardWillHide()メソッドは呼び出していません。何が間違っていたのですか?通知、キーボード隠し
'keyboardWillShow'メソッドも表示します。 –
あなたはテキストの代理人を有効にしていますかfiedl –
keyboardWillShowメソッドも追加しました。 –