我在paintcode中有一个样式包,其中一个样式包绘图方法只需要一个参数 - 有什么方法可以使用UIView.animateWithDuration(etc ..)来设置该参数的动画,以便我的视图更新顺畅吗?
3 个答案:
答案 0 :(得分: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
答案 1 :(得分:1)
Paintcode在其FAQ部分为您提供了3个选项:
- 使用UIView和NSTimer进行动画
- 具有CALayer自定义动画属性的动画
- 具有自定义动画属性和CALayer委托的动画
其中一些产品的性能优于其他产品,您可以直接从他们的网站下载一个示例项目(Swift和Objective-C)。
参考:
https://www.paintcodeapp.com/faq/animate-drawings-made-paintcode
答案 2 :(得分:0)
我最终使用PRTween项目来动画我的PaintCode项目。你可以阅读它here。