Is there any way to animate Paintcode variables?

2.5k views Asked by At

I have a stylekit in paintcode with one stylekit drawing method that takes a single parameter - is there any way I can use UIView.animateWithDuration(etc..) to animate that parameter so my view updates smoothly?

3

There are 3 answers

3
Mike Wrather On

You won't do animateWithDuration because that creates the keyframes for you and that's what you're doing with the variables you pass into the draw method generated by PaintCode.

You'll want to implement a custom UIView. Create a property for the custom class that holds the variable value for the param your drawing method accepts. Overwrite drawRect in order to call the StyleKit draw method and pass in the local variable that holds the value for the variable.

Then you'll use an NSTimer to iterate through a values over time, updating the custom UIView's property with each iteration. The trick is that when the property is updated you'll need to call self.setNeedsDisplay (swift) or [self setNeedsDisplay:YES]; (obj-c).

There is a great blog post on it available here: https://medium.com/a-first-project-with-paintcode/animating-the-arrow-6e61104b321b

0
Sergio Maldonado On

Paintcode gives you 3 options in its FAQ section:

  • Animation with UIView and NSTimer
  • Animation with custom animatable property of CALayer
  • Animation with custom animatable property and delegate of CALayer

Some of them have better performance than the others, and you can download an example project (Swift and Objective-C) directly from their website.

Reference: https://www.paintcodeapp.com/faq/animate-drawings-made-paintcode

2
Mark Alldritt On

I ended up using the PRTween project to animate my PaintCode project. You can read about it here.