键盘将显示未调用的通知iOS 12

时间:2018-09-22 22:09:37

标签: ios swift notifications keyboard ios12

在我的应用中,我希望收到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中有什么新原因导致此问题吗?否则,是否有不被调用的特定原因?谢谢你的帮助。

0 个答案:

没有答案