[翻译] JNWSpringAnimation

简介:

JNWSpringAnimation

https://github.com/jwilling/JNWSpringAnimation

 

JNWSpringAnimation is a subclass of CAKeyframeAnimation that adds support for creating damped harmonic animations.

JNWSpringAnimation 是 CAKeyframeAnimation 的子类,它支持创建阻尼动画效果。

 

Getting Started

Although JNWSpringAnimation is a subclass of CAKeyframeAnimation, it should be treated as if it were a subclass of CABasicAnimation.

尽管,JNWSpringAnimation 是 CAKeyframeAnimation 的子类,但是,你应该把他当做 CABasicAnimation 的子类来使用:)。

 

To get started, copy the four source files into your project.

把4个源文件拷贝到你的工程当中。

 

The animation can be created by using the dedicated initializer, +animationWithKeyPath:. Alternatively, the animation can be created using +animation and by setting the key path afterwards. The full list of currently-compatible animatable properties is available in the header.

你可以使用专用的初始化方法 +animationWithKeyPath:。当然,你也可以使用 +animation 方法,之后再来设置 keyPath 。目前所有兼容的属性动画都包含在头文件当中。

JNWSpringAnimation *animation = [JNWSpringAnimation animationWithKeyPath:@"position.x"];

Next, the fromValue and toValue properties must be set for the interpolated values to be calculated correctly.

下一步,fromeValue 与 toValue 属性需要插入正确的值哦。

animation.toValue = @(toX);
animation.fromValue = @(currentX);

 

Finally, the values for the spring constants can optionally be changed. Currently, stiffnessdamping, andmass are available for modification.

最后,阻尼动画的一些参数也可以修改,目前包括 stiffness(生硬程度),damping(衰弱程度?)以及mass(质量)。

animation.mass = 30; // this will move extremely slowly
// and so on

 

The animation itself can be applied like any other subclass of CAAnimation, namely -addAnimation:forKey: on any CALayer.

这个动画本身可以被任何CAAnimation的子类接收,你可以将他添加到CALayer中。

 

What's this for?

This was created in my desire to have an open-source version of the (currently private) CASpringAnimationwhich was discovered in iOS 6.

Spring animations, when used appropriately, can really enhance the way your app feels to the user by connecting in physical simulations with an app's interface. And besides, who doesn't love messing around with springs?

 

What's left to do?

I created this as a weekend project, so the implementation is still somewhat unfinished. Compared toCASpringAnimation, the velocity property is still unimplemented. Pull requests are welcome.

这只是我的小项目中的一部分,所以有些东西还不完善。

 

目录
相关文章
|
存储 自然语言处理 前端开发
从零写一个Recoil(翻译)
Rewriting Recoil from scratchrecoil是facebook编写的一个库,它之所以诞生是因为人体工程学、context的性能问题和useState。这是一个非常聪明的库,几乎每个人都会找到它的用途——如果你想了解更多,请查看这段解释视频。刚开始我被图论和recoil惊到了,但渐渐的理解后,感觉也没那么特别了。也许我也可以实现一个类似的东西。我自己实现的版本和recoil
238 0
从零写一个Recoil(翻译)
|
存储 iOS开发 Perl
|
安全 开发工具 C#