SWIFT 4无法使用高度

  • 本文关键字:高度 SWIFT swift cgrect
  • 更新时间 :
  • 英文 :


我正在使用Swift 4&获取以下错误:

实例成员'高度'不能在类型的'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)

我不知道为什么,任何帮助!

heightCGRect结构的属性。您正在访问它,就像是类方法一样。由于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
        })

最新更新