【发布时间】:2020-06-05 19:35:14
【问题描述】:
我的函数“keyboardWillShown”有问题。所以我想要的是我的菜单在打开时正好出现在键盘上方。它在 Iphone 8 plus、8、7、6 上完美运行。但是当我在模拟器上运行 Iphone 11 时,结果如下。
Picture of how it looks in Iphone 11
这是我的代码:
@objc func keyboardWillShown(notification: NSNotification) {
let info = notification.userInfo!
let keyboardFrame: CGRect = (info[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
UIView.animate(withDuration: 0.1, animations: { () -> Void in
self.keyboardConstrains.constant = keyboardFrame.size.height
})
}
调用函数
override func viewWillAppear(_ animated: Bool) {
NotificationCenter.default.addObserver( self, selector: #selector(keyboardWillShown(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil )
}
override func viewWillDisappear(_ animated: Bool) {
NotificationCenter.default.removeObserver( self,name: UIResponder.keyboardWillShowNotification, object: nil )
}
【问题讨论】:
标签: ios swift iphone xcode keyboard