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

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     }

 

 

你可能感兴趣的:(animation)