[翻译] AnimatedPath 动画路径(持续更新)
2014-04-06 06:50
302 查看
AnimatedPath
动画路径
感谢原作者分享精神,有空补上使用教程AnimatedPathexploresusingthe
CAMediaTimingprotocoltointeractivelycontrolthedrawingofapath.
AnimatedPath尝试使用CAMediaTiming协议来控制绘制一条路径。
Basicusage
基本使用方法
基本使用方法
Step1:DrawaPath
第一步:绘制一条路径
Taparoundthescreentoaddpointstoapath.点击屏幕来给路径添加点第一步:绘制一条路径
Dragexistingpointstomovethem.拖动存在的点
Tapandholdexistingpointstoremovethem.长按着一个点来删除这个点
Step2:Animate
第二步:动画
Thepathisrenderedusinga第二步:动画
CAShapeLayerwith
speed==0.
Thelayerhasananimationforits
strokeEndkeypathwitha
fromValueof0anda
toValueof1.
Sincethelayer's
speed==0,adjustingthelayer's
timeOffsetcontrolsthetimeatwhichtheanimationisrendered.
Theslideratthetopofthescreenadjuststhelayer's
timeOffset.
使用CAShapeLayer来渲染路径,设置speed=0
这个layer用strokeEnd作为关键帧路径,其值从0到1变化
当layer的speed为0时,操作layer的timeOffset来控制时间,动画就是通过这个来渲染的
屏幕上方的slider控制器操作着layer的timeOffset
GettingtheSetupRight
如何正确的设置
Themostdifficultpartofputtingthisexampletogetherwasunderstandinghowtoaddtheanimationtothelayerandstillbeabletocontroltheanimation'sprogressviathe如何正确的设置
timeOffset.Here'swhatworked:
最难的部分就是怎么把动画加进layer中去,而且,还能够控通过timeOffset来控制动画的百分比进度,以下代码描述了怎么运作的:
CABasicAnimation*animation=[CABasicAnimationanimationWithKeyPath:NSStringFromSelector(@selector(strokeEnd))];
animation.fromValue=@0.0;
animation.toValue=@1.0;
animation.removedOnCompletion=NO;
animation.duration=kDuration;
[self.pathBuilderView.pathShapeView.shapeLayeraddAnimation:animationforKey:NSStringFromSelector(@selector(strokeEnd))];
self.pathBuilderView.pathShapeView.shapeLayer.speed=0;
self.pathBuilderView.pathShapeView.shapeLayer.timeOffset=0.0;
[CATransactionflush];
self.pathBuilderView.pathShapeView.shapeLayer.timeOffset=kInitialTimeOffset;
Theendresultofthisapproachisthattheanimationhasa
beginTimeof0andtheshapelayerrendersitattime
kInitialTimeOffset.
结果呢,就是动画有一个beginTime,从0开始,然后,shapelayer就根据kInitialTimeOffset来渲染。
The
[CATransactionflush]isrequiredbecauseitforcesthesystemtogivetheanimationaddedtothelayera
beginTime.Theanimation's
beginTimeiscalculatedbyaddingitsinitialvalue(itsvaluebeforebeingaddedtothelayer)tothelayer'scurrenttime.Thisiswhythelayer's
timeOffsetmustbesetto0ratherthan
kInitialTimeOffsetwhentheanimationisadded.Otherwise,theanimation's
beginTimewillhavealreadytaken
kInitialTimeOffsetintoaccountsuchthattheanimationisaddedtothetimerange
(kInitialTimeOffset,kInitialTimeOffset+kDuration)insteadof
(0,kDuration).
这个方法[CATransactionflush]是必须的,因为,他能够强制的让系统给添加了动画的layer一个beginTime。这个动画的beginTime是添加了layer的起始值,这就是为什么layer的timeOffset必须设置成0,而不是kInitalTimeOffset。所以,这个动画的beginTime会考虑到kInitialTimeOffset,然后他的时间就被设置成了(kIntialTimeOffset,kInitialTimeOffset+kDuration),而不是(0,kDuration)【能力有限,此段翻译不准,见谅】
MoreInfo
ThisexamplewasinspiredbyApple's
这个例子的灵感来自于
苹果的
相关文章推荐
- 每天一题LeetCode系列(有翻译,注释,持续更新~)
- ios动画效果集锦(持续更新)
- 《Entity Framework 6 Recipes》中文翻译系列 目录篇 -持续更新
- android常用动画[持续更新]
- 2017.3.27 集成modeler后的一些主要路径(持续更新)
- 《Entity Framework 6 Recipes》中文翻译系列 目录篇 -持续更新
- 《统计自然语言处理基础》中文版翻译勘误表,持续更新
- 使用path制作各类型动画路径
- Play 2.0 中文资料--翻译附注解(持续更新中)
- [持续更新] 神经机器翻译论文汇总 Papers on Neural Machine Translation
- 译文:Javascript的12个怪癖【未翻译完持续更新】
- M_LROOT,LD_LIBRARY_PATH, “Not all extension Dlls were loaded”问题原因及解决方法(持续更新)
- 每天一题LeetCode系列(有翻译,注释,持续更新~)
- Silverlight & Blend动画设计系列十一:沿路径动画(Animation Along a Path)
- 翻译windows internals 第12章文件系统 (持续更新)NTFS
- Silverlight & Blend动画设计系列十一:沿路径动画(Animation Along a Path)
- 动画动漫网址集锦持续更新
- 每天一题LeetCode系列(有翻译,注释,持续更新~)
- [翻译] ECMAScript 6(持续更新)
- Android各类交互良好动画集锦(持续更新)