CalZone
CalZone

Reputation: 1721

Animation in core graphics

I followed this awesome Rey Wenderlich tutorial to make an Bezier arc and increment/decrement values. But how to animate the arch instead of just step-up and step-down?

http://www.raywenderlich.com/90690/modern-core-graphics-with-swift-part-1

I tried putting animation block in custom property declaration, which I dont think is the right place to do it and xcode doesn't let me do it anyway.

    @IBInspectable var counter: Int = 5 {
    didSet {
        if counter <=  NoOfGlasses {
            //the view needs to be refreshed

            UIView.animateWithDuration(0.2, animations: {
                    setNeedsDisplay()
                }, completion:nil
            )


        }
    }
}

Also tried to put the increment in animation block in View controller, didn't work.

@IBAction func btnPushButton(sender: AnyObject) {
    UIView.animateWithDuration(0.2, animations: {
        self.arcView.counter = self.arcView.counter + 10
        self.counterLabel.text = String(self.arcView.counter)

        }, completion:nil
    )

}

Upvotes: 0

Views: 632

Answers (1)

matt
matt

Reputation: 535989

Are you describing this sort of thing?

enter image description here

That's a simpler example - it's just a drawn triangle - but it's the same idea, if I'm understanding you correctly: we are animating the difference between one drawing and another.

Basically you have two choices. The easy way is to use CAShapeLayer, which animates for you automatically when you change its path. The other choice is to do what I'm doing here, which is to create a custom animatable property - in this case, a property representing the x-position of the bottom point of the triangle.

Upvotes: 1

Related Questions