博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[翻译] JNWSpringAnimation
阅读量:4321 次
发布时间:2019-06-06

本文共 2290 字,大约阅读时间需要 7 分钟。

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.

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

 

 

转载于:https://www.cnblogs.com/YouXianMing/p/3750085.html

你可能感兴趣的文章
java常见面试题及三大框架面试
查看>>
懒惰的肥兔博文导读
查看>>
[db] mongodb 存取修改简单小实例
查看>>
面试百题003——求子数组的最大和
查看>>
jq.validate 自定义验证两个日期
查看>>
公布一个以前写的随机数生成的方法
查看>>
AtCoder Regular Contest 077 被虐记&题解
查看>>
禁止ios10双指缩放
查看>>
LUOGU P1505 [国家集训队]旅游 (树链剖分+线段树)
查看>>
BZOJ 3509: [CodeChef] COUNTARI(fft+分块)
查看>>
flask源码解读05: Context(AppContext, RequestContext)
查看>>
css实现弹出层显示阻止滚动条滚动
查看>>
ping IP 带时间戳循环显示并写入日志(windos版+linux版)
查看>>
自学MVC看这里——全网最全ASP.NET MVC 教程汇总
查看>>
mediaxyz访谈录:ffmpeg的码率控制
查看>>
CenTOS7使用ACL控制目录权限,只给某个用户访问特定目录
查看>>
七天入门统计力学-第2天 系综与配分函数
查看>>
ubuntu server 10.04 apache2配置多个虚拟主机
查看>>
python标准库xml.etree.ElementTree的bug
查看>>
Tomcat服务器介绍和使用
查看>>