Swift键盘高度返回0

时间:2018-01-05 12:58:21

标签: ios swift

我的代码第一次正常工作时单击按钮我得到了键盘高度,但问题是当它解散时我再次调用它返回高度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)")
    }
}

1 个答案:

答案 0 :(得分:2)

UIKeyboardFrameEndUserInfoKey检查它会不会有效?