Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to animate Paintcode variables?

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?

like image 652
teo751 Avatar asked Jun 15 '15 05:06

teo751


2 Answers

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

like image 144
Mike Wrather Avatar answered Oct 16 '22 08:10

Mike Wrather


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

like image 27
Sergio Maldonado Avatar answered Oct 16 '22 09:10

Sergio Maldonado