iOS 10 的 UIViewPropertyAnimator

let AView = UIView(frame: CGRect(x: 50, y: 200, width: 50, height: 30))
AView.backgroundColor = UIColor.red
self.view.addSubview(AView)
let finalPoint = CGPoint(x: 250, y: 200)
        
let animator = UIViewPropertyAnimator(duration: 1.0, curve: .easeOut) {
    AView.center = finalPoint
}
animator.startAnimation()
// 阻尼系数值 0~1
let animator = UIViewPropertyAnimator(duration: 1.0, dampingRatio: 0.4) { 
    AView.center = finalPoint
    AView.alpha = 0.3
}
// 添加动画
animator.addAnimations {
    AView.alpha = 0.0
}
// 你还可以向运行中的动画添加动画块,该动画块将立即使用剩余时间作为新动画的持续时间来执行。
        
 // 当动画完成时会被触发的
animator.addCompletion { (position) in
    // code...
}
animator.startAnimation(afterDelay:3) // 延时
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容