我在试着移动
constraintToBottom.constant
的
UIView
我的朋友呢
UITextField
显示后位于键盘上方。我设置了
Notification
观察者,但由于某种原因它不起作用。
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)
}
@objc func keyboardWillShow(_ notification: Notification) {
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
UIView.animate(withDuration: 0.3, animations: {
self.constraintToBottom.constant = keyboardSize.height
print("constant", self.constraintToBottom.constant)
})
}
}
当我打印
常数346.0
然而,这个
UIView视图