1,CAKeyframeAnimation介绍
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
let animation = CAKeyframeAnimation(keyPath: "position")//设置5个位置点let p1 = CGPointMake(0.0, 0.0)let p2 = CGPointMake(300, 0.0)let p3 = CGPointMake(0.0, 400)let p4 = CGPointMake(300, 400)let p5 = CGPointMake(150, 200)//赋值animation.values = [NSValue(CGPoint: p1), NSValue(CGPoint: p2), NSValue(CGPoint: p3), NSValue(CGPoint: p4), NSValue(CGPoint: p5)]//每个动作的时间百分比animation.keyTimes = [NSNumber(float: 0.0), NSNumber(float: 0.4), NSNumber(float: 0.6), NSNumber(float: 0.8), NSNumber(float: 1.0), ]animation.delegate = selfanimation.duration = 6.0self.imageView.layer.addAnimation(animation, forKey: "Image-Move") |
3,可以设置动画代理,监听开始和结束动作
|
1
2
3
4
5
6
7
8
9
|
animation.delegate = selfoverride func animationDidStart(anim: CAAnimation!) { println("动画开始")}override func animationDidStop(anim: CAAnimation!, finished flag: Bool) { println("动画结束")} |
Swift - 使用CAKeyframeAnimation实现关键帧动画
原文:http://www.cnblogs.com/Free-Thinker/p/4843451.html