Swift-use cakeyframeanimation for keyframe animations

Source: Internet
Author: User

1,cakeyframeanimation Introduction

Cakeyframeanimation can implement key-frame animations, which can be used to animate a property according to a string of values, as if it were a frame-by-frame production.
2, using the sample (set five key coordinates, the picture is moved by key points in turn)
123456789101112131415161718192021 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, you can set the animation agent, listen to start and end action

123456789 animation.delegate = selfoverride func animationDidStart(anim: CAAnimation!) {    println("动画开始")}override func animationDidStop(anim: CAAnimation!, finished flag: Bool) {    println("动画结束")}

Swift-use cakeyframeanimation for keyframe animations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.