当前位置: 首页 > 工具软件 > GiFHUD-Swift > 使用案例 >

swift中关键帧动画

袁青青
2023-12-01
  @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")
    }
 类似资料: