Swift 的 POPSpringAnimation toValue CGPoint 错误

POPSpringAnimation toValue CGPoint bug with Swift

我在使用 POP 动画框架和 Swift

时遇到 CGPoints 的奇怪错误

我一直使用 Objective-C 和 Pop 来制作动画,但现在我尝试用 Swift 做同样的事情,当我尝试 运行 下一个代码时死于以下错误:由于未捕获的异常 'Invalid value' 而终止应用程序,原因:'NSPoint: {100, 20} should be of type int' 然后我尝试只用一个 Int 值来做它并且它有效但只是动画 X 轴并将 Y 轴保留为 0.

func interact(){
        var spAn = POPSpringAnimation(propertyNamed:kPOPViewCenter)
        spAn.velocity = 1
        if opened{
            spAn.toValue = NSValue(CGPoint: CGPoint(x: -100, y: 20))
            opened = false
        }
        else{
            spAn.toValue = NSValue(CGPoint: CGPoint(x: 100, y: 20))
            opened = true
        }
        self.pop_addAnimation(spAn, forKey: "center")
    }

您的 velocitytoValue 必须是同一类型。

由于您将 velocity 设置为 1(int 类型),它期望您的 toValue 也是 int 类型。

我遇到了同样的问题(使用 Obj-c),但它告诉我我的 toValue 应该是 CGPoint 类型。我最初使用的动画 属性 需要 CGPoint,但当我更改它时,我也忘记更改 velocity 类型。