swiftcgpointfacebook-pop

POPSpringAnimation toValue CGPoint bug with Swift


I have an strange bug with CGPoints using POP Animation Framework and Swift

I've always used Objective-C and Pop to make animations but now I'm trying to do the same with Swift and when I try to run the next code it dies with the following error: Terminating app due to uncaught exception 'Invalid value', reason: 'NSPoint: {100, 20} should be of type int' Then I try to do it with just an Int value and it works but just animate X axis and leave Y axis as 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")
    }

Solution

  • Your velocity and toValue have to be the same type.

    Since you set your velocity to 1 (of type int) it expects your toValue to be of type int as well.

    I had this same problem (using Obj-c), but it was telling me my toValue should be of type CGPoint. I had initially been using an animation property that expected a CGPoint and when I changed it I forgot to change the velocity type as well.