不能使用Swift 4 CGRect高度
我正在使用swift 4&出现以下错误: 实例成员“height”不能用于类型“CGRect” 使用以下代码时:不能使用Swift 4 CGRect高度,swift,cgrect,Swift,Cgrect,我正在使用swift 4&出现以下错误: 实例成员“height”不能用于类型“CGRect” 使用以下代码时: let userInfo = notification.userInfo! let keyboardFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue).cgRectValue let keyboardFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] a
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
})