2016-12-16 11 views
1

UIViewPropertyAnimatorでユーザーインタラクティブアニメーションを利用したい場合は、オブジェクトを時計回りに360度アニメーションしますか? (少しハックされていない場合?)UIViewPropertyAnimatorを使って360度回転する方法

幸い
// Does not animate 
let animator = UIViewPropertyAnimator(duration: 2, curve: .linear) { 
    let radians = Angle(360).radians // 6.28318530717959 
    view.transform = view.transform.rotated(by: CGFloat(radians)) 
} 
// (Using RxSwift to handle the user interaction via UISlider, 
// but that can be ignored as an implementation detail for this question.) 
let scrubs = slider.rx.value.asDriver() 
scrubs.drive(onNext: { (value:Float) -> Void in 
    animator.fractionComplete = CGFloat(value) 
}) 

答えて

2

UIViewPropertyAnimatorは、これは非常に簡単になります。ただ、180ºのために2つのアニメーション、それぞれを作る:これはfractionCompleteを経由して「スクラブ」、停止、一時停止、完成または開始することができるもののアニメーションのように動作します

let animator = UIViewPropertyAnimator(duration: 2, curve: .linear) { 
    let radians = Angle(180).radians // 3.14159265358979 
    view.transform = view.transform.rotated(by: CGFloat(radians)) 
} 
animator.addAnimations { 
    let radians = Angle(180).radians 
    view.transform = view.transform.rotated(by: radians) 
} 

Example playground

関連する問題