swift中关键帧动画

来源:互联网 发布:淘宝代运营骗局 编辑:程序博客网 时间:2024/05/18 00:14
  @IBOutlet weak var bgView: UIView!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        
     
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        let animation = CAKeyframeAnimation()
        
        animation.duration = 0.5
        
        
        let value1 = bgView.frame.origin
        
        let value2 = CGPoint.init(x: 0, y: 0)
        
        let  value3 = CGPoint(x: 400, y: 200)
        
        
        
        animation.values =  NSArray(objects: NSValue(cgPoint: value1),NSValue(cgPoint: value2),NSValue(cgPoint: value3)) as! [Any]
        
        
        
        bgView.layer.add(animation, forKey: "position")
    }
0 0