我正在使用swift 4并收到以下错误:
实例成员'height'不能用于'CGRect'类型
使用以下代码时:
let userInfo = notification.userInfo!
let keyboardFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue).cgRectValue
let keyboardFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue).cgRectValue
let changeInHeight = (CGRect.height(keyboardFrame) + 40) * (show ? 1 : -1)
我无法弄清楚为什么,任何帮助非常感谢!
height
是CGRect
结构的财产。您正在访问它,就像它是一个类方法。由于keyboardFrame
是CGRect
类型,你需要keyboardFrame.height
。
let changeInHeight = (keyboardFrame.height + 40) * (show ? 1 : -1)
var userInfo = notification.userInfo!
let keyboardFrame:CGRect = (userInfo[UIResponder.keyboardFrameBeginUserInfoKey] as! NSValue).cgRectValue
let animationDurarion = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as! TimeInterval
let changeInHeight = (keyboardFrame.height + 40) * (show ? 1 : -1)
UIView.animate(withDuration: animationDurarion, animations: { () -> Void in
self.bottomConstraint.constant += changeInHeight
})