码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发——动画编程Swift篇&(五)CAKeyframeAnimation

时间:2015-06-07 23:18:52      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:

CAKeyframeAnimation

 

 1     //CAKeyframeAnimation-关键针动画
 2     @IBAction func cakFly()
 3     {
 4         let animation = CAKeyframeAnimation(keyPath: "position")
 5         
 6         //设置5个位置点
 7         let p1 = CGPointMake(0.0, 0.0)
 8         let p2 = CGPointMake(320, 0.0)
 9         let p3 = CGPointMake(0, 460.0)
10         let p4 = CGPointMake(320.0, 460.0)
11         let p5 = CGPointMake(160.0, 200.0)
12         
13         //赋值
14         animation.values = [NSValue(CGPoint: p1),NSValue(CGPoint: p2),NSValue(CGPoint: p3),NSValue(CGPoint: p4),NSValue(CGPoint: p5)]
15         
16         
17         //每个动作的 时间百分比
18         animation.keyTimes = [NSNumber(float: 0.0),NSNumber(float: 0.4),NSNumber(float: 0.6),NSNumber(float: 0.8),NSNumber(float: 1.0)]
19       
20         animation.delegate = self
21         animation.duration = 5.0
22         
23         self.testImageView.layer.addAnimation(animation, forKey: "Image-Fly")
24     }
25     
26     //动画代理
27     override func animationDidStart(anim: CAAnimation!)
28     {
29         //动画开始
30     }
31     
32    override func animationDidStop(anim: CAAnimation!, finished flag: Bool)
33     {
34         //动画结束
35     }

 

 

iOS开发——动画编程Swift篇&(五)CAKeyframeAnimation

标签:

原文地址:http://www.cnblogs.com/iCocos/p/4559288.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!