我尝试使用键盘通知,因此我可以根据键盘是显示还是隐藏来向上或向下移动滚动视图中的信息。我的问题是当我第一次点击任何文本字段时。我无法理解为什么当KeyboardDidShow的通知触发时它会触发KeyboardWillHide的通知......
这是相关的代码。
func registerKeyboardNotifications() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardDidShow:", name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
}
func unregisterKeyboardNotifications() {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
func keyboardDidShow(notification: NSNotification) {
NSLog("Keyboard did show")
}
func keyboardWillHide(notification: NSNotification) {
NSLog("Keyboard will hide")
}
这是输出: