[翻译] AnimatedPath 动画路径(持续更新)
AnimatedPath
动画路径
感谢原作者分享精神,有空补上使用教程
https://github.com/twotoasters/AnimatedPath
AnimatedPath explores using the CAMediaTiming
protocol to interactively control the drawing of a path.
AnimatedPath 尝试使用 CAMediaTiming 协议来控制绘制一条路径。
Basic usage
基本使用方法
Step 1: Draw a Path
第一步:绘制一条路径
- Tap around the screen to add points to a path. 点击屏幕来给路径添加点
- Drag existing points to move them. 拖动存在的点
- Tap and hold existing points to remove them. 长按着一个点来删除这个点
Step 2: Animate
第二步:动画
- The path is rendered using a
CAShapeLayer
withspeed == 0
. - The layer has an animation for its
strokeEnd
key path with afromValue
of 0 and atoValue
of 1. - Since the layer's
speed == 0
, adjusting the layer'stimeOffset
controls the time at which the animation is rendered. - The slider at the top of the screen adjusts the layer's
timeOffset
. - 使用 CAShapeLayer 来渲染路径,设置 speed = 0
- 这个 layer 用 strokeEnd 作为关键帧路径,其值从 0 到 1 变化
- 当 layer 的 speed 为0时,操作 layer 的 timeOffset 来控制时间,动画就是通过这个来渲染的
- 屏幕上方的 slider 控制器操作着 layer 的 timeOffset
Getting the Setup Right
如何正确的设置
The most difficult part of putting this example together was understanding how to add the animation to the layer and still be able to control the animation's progress via the timeOffset
. Here's what worked:
最难的部分就是怎么把动画加进 layer 中去,而且,还能够控通过 timeOffset 来控制动画的百分比进度,以下代码描述了怎么运作的:
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:NSStringFromSelector(@selector(strokeEnd))];
animation.fromValue = @0.0;
animation.toValue = @1.0;
animation.removedOnCompletion = NO;
animation.duration = kDuration;
[self.pathBuilderView.pathShapeView.shapeLayer addAnimation:animation forKey:NSStringFromSelector(@selector(strokeEnd))];
self.pathBuilderView.pathShapeView.shapeLayer.speed = 0;
self.pathBuilderView.pathShapeView.shapeLayer.timeOffset = 0.0;
[CATransaction flush];
self.pathBuilderView.pathShapeView.shapeLayer.timeOffset = kInitialTimeOffset;
The end result of this approach is that the animation has a beginTime
of 0 and the shape layer renders it at time kInitialTimeOffset
.
结果呢,就是动画有一个 beginTime,从 0 开始,然后,shapelayer 就根据 kInitialTimeOffset 来渲染。
The [CATransaction flush]
is required because it forces the system to give the animation added to the layer a beginTime
. The animation's beginTime
is calculated by adding its initial value (its value before being added to the layer) to the layer's current time. This is why the layer's timeOffset
must be set to 0 rather thankInitialTimeOffset
when the animation is added. Otherwise, the animation's beginTime
will have already taken kInitialTimeOffset
into account such that the animation is added to the time range(kInitialTimeOffset, kInitialTimeOffset + kDuration)
instead of (0, kDuration)
.
这个方法 [CATransaction flush] 是必须的,因为,他能够强制的让系统给添加了动画的 layer 一个 beginTime 。这个动画的 beginTime 是添加了 layer 的起始值,这就是为什么 layer 的 timeOffset 必须设置成 0 ,而不是 kInitalTimeOffset。所以,这个动画的 beginTime 会考虑到 kInitialTimeOffset ,然后他的时间就被设置成了 (kIntialTimeOffset, kInitialTimeOffset + kDuration), 而不是 (0, kDuration)【能力有限,此段翻译不准,见谅】
More Info
- This example was inspired by Controlling Animation Timing by David Rnnqvist
- Apple's Timing, Timespaces, and CAAnimation is a helpful resource.
- 这个例子的灵感来自于 Controlling Animation Timing by David Rnnqvist
- 苹果的 Timing, Timespaces, and CAAnimation 也很管用
[翻译] AnimatedPath 动画路径(持续更新)的更多相关文章
- iOS动画相关(持续更新)
1.When my application is entering background, because the user push the home button, the animations ...
- 《Entity Framework 6 Recipes》中文翻译系列 目录篇 -持续更新
为了方便大家的阅读和学习,也是响应网友的建议,在这里为这个系列做一个目录.在目录开始这前,我先来回答之前遇到的几个问题. 1.为什么要学习EF? 这个问题很简单,项目需要.这不像学校,没人强迫你学习! ...
- BAT 前端开发面经 —— 吐血总结 前端相关片段整理——持续更新 前端基础精简总结 Web Storage You don't know js
BAT 前端开发面经 —— 吐血总结 目录 1. Tencent 2. 阿里 3. 百度 更好阅读,请移步这里 聊之前 最近暑期实习招聘已经开始,个人目前参加了阿里的内推及腾讯和百度的实习生招聘, ...
- Android 常用开源库总结(持续更新)
前言 收集了一些比较常见的开源库,特此记录(已收录350+).另外,本文将持续更新,大家有关于Android 优秀的开源库,也可以在下面留言. 一 .基本控件 TextView HTextView 一 ...
- 【持续更新】JavaScript常见面试题整理
[重点提前说]这篇博客里的问题涉及到了了JS中常见的的基础知识点,也是面试中常见的一些问题,建议初入职场的园友Mark收藏,本文会持续更新~ 1. 引入JS的三种方式 1.在HTML标签中直接使用,直 ...
- 【前端】Util.js-ES6实现的常用100多个javaScript简短函数封装合集(持续更新中)
Util.js (持续更新中...) 项目地址: https://github.com/dragonir/Util.js 项目描述 Util.js 是对常用函数的封装,方便在实际项目中使用,主要内容包 ...
- android 量产软件改动信息(持续更新)
http://blog.csdn.net/xubin341719/article/details/8449352 关键词:android 4.0默认语言蓝牙名称 MTP名称默认时区关于平板电脑 内核版 ...
- Python常用组件、命令大总结(持续更新)
Python开发常用组件.命令(干货) 持续更新中-关注公众号"轻松学编程"了解更多. 1.生成6位数字随机验证码 import random import string def ...
- JVM面试题(史上最强、持续更新、吐血推荐)
文章很长而且持续更新,建议收藏起来,慢慢读! 高并发 发烧友社群:疯狂创客圈(总入口) 奉上以下珍贵的学习资源: 疯狂创客圈 经典图书 : 极致经典 + 社群大片好评 < Java 高并发 三部 ...
随机推荐
- js与jquery的动态加载脚本文件
jquery动态加载 jQuery.getScript(url,[callback]) js动态加载 function loadJs(name) { document.write('<scrip ...
- 易普优APS与国外知名高级计划排程系统对比
众所周知软件执行效率受制于硬件性能,市面上的APS产品多为单机版本,企业要应用好APS,保证紧急插单.计划下发全程无忧,用户电脑硬件性能是不容忽视的一大瓶颈.APS的直接用户是车间管理人员.计划员,而 ...
- mysql的第一个程序
每次写java链接数据怎么写,这一次做一个总结,方便参考. 1.在mysql上下载mysql驱动jar包 2.下载的驱动包 3.程序目录 4.程序 package mysqlTest; import ...
- Python爬虫个人记录(四)利用Python在豆瓣上写一篇日记
涉及关键词:requests库 requests.post方法 cookies登陆 version 1.5(附录):使用post方法登陆豆瓣,成功! 缺点:无法获得登陆成功后的cookie,要使用js ...
- Spark入门3(累加器和广播变量)
一.概要 通常情况下,当向Spark操作传递一个函数时,它会在一个远程集群节点上执行,它会使用函数中所有变量的副本.这些变量被复制到所有的机器上,远程机器上并没有被更新的变量会向驱动程序回传.在任务之 ...
- PHP接入微信H5支付
开发前配置 进行代码接入前,需在微信后台填写授权回调域名,此域名必须经过ICP备案 开发主要流程 用户下单时选择微信支付 商户进行业务逻辑处理并调用微信统一下单接口,微信H5交易类型为:trade_t ...
- CodeForces528A (STLset)
题面 CodeForces 题解 横着切和竖着切是互相不影响的. 假设现在横着切成了很多段,显然此时面积最大的矩形的一边长就是这些段中长度最长的一段.竖着切的也是一样的. 所以就可以用\(set\)来 ...
- Linux驱动程序中的并发控制
<临界区> a:对共享资源进行访问的代码称为临界区. <原子操作> a:原子操作用于执行轻量级,仅仅执行一次的的操作比如修改计数器,有条件的增加值,设置某一位.所谓 ...
- Windows安装绿色版git管理软件GitStack 2.3.8
1.原来 GitStack 是安装在局域网的,为了更好开展工作,迁移到公网的服务器.(安全性未知) 2.公网服务器已经在运行一个 Apache 2.4 (占用80端口): 3.GitStack 2. ...
- Codeforces Round #222 (Div. 1) C. Captains Mode 状压
C. Captains Mode 题目连接: http://codeforces.com/contest/377/problem/C Description Kostya is a progamer ...