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
}
我添加了两个通知(键盘向上,向下)。当我触摸返回按钮时,我想让键盘隐藏。但keyboardWillHide()方法没有调用。我错了什么或错过了什么?通知,键盘隐藏
也显示'keyboardWillShow'方法。 –
你是否启用了你的文本的代表fiedl –
我刚刚添加了keyboardWillShow方法。 –