我的代码第一次正常工作时单击按钮我得到了键盘高度,但问题是当它解散时我再次调用它返回高度0,这里的任何帮助都是代码
@IBAction func showCaseProgressSliderBtn(_ sender: Any){
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: .UIKeyboardWillShow, object: nil)
}
@objc func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
let keyboardHeight = keyboardSize.height
keyboardHeightCG = keyboardHeight
print("keyboard is \(keyboardHeightCG)")
}
}
答案 0 :(得分:2)
用UIKeyboardFrameEndUserInfoKey
检查它会不会有效?