iOS 核心动画编程

//

//  ViewController.swift

//  ios核心动画编程

//

//  Created by Macx on 18/9/16.

//  Copyright (c) 2018年 learn. All rights reserved.

//

 

import UIKit

 

class ViewController: UIViewController {

 

    var mylayer = CALayer()

    override func viewDidLoad() {

        super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.

        self.testLayerProperty()

    }

 

    @IBAction func start(sender: AnyObject) {

        self.caBasicAnimate()

        

    }

    

    func testLayerProperty(){

        mylayer = CALayer()

        mylayer.backgroundColor = UIColor.magentaColor().CGColor

        mylayer.borderColor = UIColor.yellowColor().CGColor

        mylayer.borderWidth = 3.0

        mylayer.cornerRadius = 10.0

        mylayer.shadowColor = UIColor.whiteColor().CGColor

        mylayer.shadowOffset = CGSizeMake(20.0, 20.0)

        mylayer.shadowOpacity = 0.2

        mylayer.frame = CGRectMake(100, 100, 100, 100)

        

        self.view.layer.addSublayer(mylayer)

    }

    //隐式动画

    func implicitAnimation(){

        mylayer.position.y += 100

    }

    //显示动画

    func caBasicAnimate(){

        var imgview = UIImageView(image: UIImage(named: "1.jpeg"))

        imgview.frame = CGRectMake(150, 200, 100, 100)

        self.view.addSubview(imgview)

        //选定角色

    

        var la = imgview.layer

        //写剧本1

        var scaleAni = CABasicAnimation(keyPath: "transform.scale")

        scaleAni.fromValue = 1.0

        scaleAni.toValue = 2.0

        scaleAni.fillMode = kCAFillModeForwards

        scaleAni.repeatCount = MAXFLOAT

        scaleAni.autoreverses = true

        scaleAni.duration = 2.0

        //写剧本2

        var opacityAni = CABasicAnimation(keyPath: "opacitty")

        opacityAni.fromValue = 0.3

        opacityAni.toValue = 1.0

        opacityAni.fillMode = kCAFillModeBackwards

        opacityAni.duration = 1.0

        opacityAni.autoreverses = true

        opacityAni.repeatCount = MAXFLOAT

        //写剧本3

        var keyAnimate = CAKeyframeAnimation(keyPath: "position")

        var value0 = NSValue(CGPoint: la.position)

        var value1 = NSValue(CGPoint: CGPointMake(la.position.x, la.position.y + 200))

        var value2 = NSValue(CGPoint: CGPointMake(la.position.x - 150, la.position.y + 200))

        var value3 = NSValue(CGPoint: CGPointMake(la.position.x - 150, la.position.y + 200))

        var value4 = NSValue(CGPoint: la.position)

        

        keyAnimate.values = [value0,value1,value2,value3,value4]

        //每一段执行时间

        keyAnimate.keyTimes = [0,0.4,0.5,0.6,1]

        

        keyAnimate.autoreverses = false

        keyAnimate.repeatCount = MAXFLOAT

        keyAnimate.duration = 7

        

        la.addAnimation(scaleAni, forKey: "group")

        la.addAnimation(keyAnimate, forKey: "keyAnimate")

        //la.addAnimation(opacityAni, forKey: "opa")

    }

    

    

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }

 

 

}

 

转载于:https://www.cnblogs.com/zhipangxiongdi/p/9661582.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值