6

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?

teo751
  • 321
  • 1
  • 4
  • 13
  • Check out [“Animating Custom Layer Properties”](http://www.objc.io/issues/12-animations/animating-custom-layer-properties/). – rob mayoff Jun 15 '15 at 05:18

3 Answers3

6

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

Mike Wrather
  • 146
  • 7
  • Is there a more efficient way to accomplish the same task? Redrawing the view on a timer (especially a fast timer) is very costly. (CPU usage is at almost 50% on my 6S just because of this.) – Jake Jul 17 '16 at 21:54
  • I agree. Is there some way to achieve the same, but without the use of a timer (as in; is there a more efficient way)? – Gerald Eersteling Dec 01 '16 at 14:20
  • Seems like you are reinventing what Core Animation does already. – wcochran Aug 08 '17 at 01:43
1

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

0

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

Mark Alldritt
  • 597
  • 1
  • 4
  • 9