美文网首页
iOS 10 的 UIViewPropertyAnimator

iOS 10 的 UIViewPropertyAnimator

作者: 42vio | 来源:发表于2016-12-27 17:20 被阅读56次
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) // 延时

相关文章

网友评论

      本文标题: iOS 10 的 UIViewPropertyAnimator

      本文链接:https://www.haomeiwen.com/subject/hgnsvttx.html