无法使用Swift 4 CGRect高度

问题描述 投票:-1回答:2

我正在使用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)

我无法弄清楚为什么,任何帮助非常感谢!

swift cgrect
2个回答
3
投票

heightCGRect结构的财产。您正在访问它,就像它是一个类方法。由于keyboardFrameCGRect类型,你需要keyboardFrame.height

let changeInHeight = (keyboardFrame.height + 40) * (show ? 1 : -1)

0
投票
 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
        })
© www.soinside.com 2019 - 2024. All rights reserved.