Swift 4 CGRect高度不能使用
Swift 4 CGRect height cannot be used
我正在使用 swift 4 并收到以下错误:
Instance member 'height' cannot be used on type '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
结构的 属性。您正在访问它,就像它是一种 class 方法一样。由于 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
})
我正在使用 swift 4 并收到以下错误:
Instance member 'height' cannot be used on type '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
结构的 属性。您正在访问它,就像它是一种 class 方法一样。由于 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
})