键盘将显示不称为iOS 12的通知

键盘将显示不称为iOS 12的通知,ios,swift,notifications,keyboard,ios12,Ios,Swift,Notifications,Keyboard,Ios12,在我的应用程序中,我想为UIResponder.keyboardWillShowNotification发出通知,以更新我文本字段的y位置。它在iOS 12之前工作;现在,它没有在我的一个视图控制器中调用(它适用于其他视图控制器)。以下是我执行此操作的代码: @objc func keyboardWillShow(_ notification: Notification) { print("keyboard will show 2") guard let frameValue:

在我的应用程序中,我想为UIResponder.keyboardWillShowNotification发出通知,以更新我文本字段的y位置。它在iOS 12之前工作;现在,它没有在我的一个视图控制器中调用(它适用于其他视图控制器)。以下是我执行此操作的代码:

@objc func keyboardWillShow(_ notification: Notification) {
    print("keyboard will show 2")
    guard let frameValue: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else {
        return
    }
    let keyboardFrame = frameValue.cgRectValue
    UIView.animate(withDuration: animationTime) {
        self.addViewBottomConstraint.constant = keyboardFrame.size.height
        self.view.layoutIfNeeded()
        print("Bottom contraint height = \(self.addViewBottomConstraint.constant)")
    }
}

@objc func keyboardWillHide(_ notification: Notification) {
    UIView.animate(withDuration: animationTime) {
        self.addViewBottomConstraint.constant = 0
        self.view.layoutIfNeeded()
    }
}

override func viewDidLoad() {
    super.viewDidLoad()

    NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)

    NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}

此处未打印“键盘将显示2”,但为具有相同通知的其他视图控制器打印。iOS 12中有什么新的东西导致了这种情况吗?否则,是否有特定的原因不调用它?谢谢你的帮助

您是否在任何位置(例如视图消失时)删除观察结果?我在Denit中执行此操作在iOS 11上在模拟器或任何尚未更新到iOS 12的设备上检查一次。登录此视图控制器的
Denit
。我打赌它会过早地消失。结果证明它在iOS 11上也不起作用。此外,我注释掉了Denit,但它仍然不起作用