I'm creating todays extension within iOS. What I'm trying to do is to animate value change on UISlider added in todays extension. Animation should proceed from start value to end value.
I tried to do it in two ways: First UIView animation
func updateSliderView(beginState:Float, duration: NSTimeInterval) {
sliderView.hidden = false
sliderView.setValue(beginState, animated: false)
UIView.animateWithDuration(duration) { () -> Void in
self.sliderView.setValue(1, animated: true)
}
}
Second with Basic Animation.
func updateSliderView(beginState:Float, duration: NSTimeInterval) {
sliderView.hidden = false
guard let _ = sliderView.layer.animationForKey("slider.animation.value") else {
let animation = CABasicAnimation(keyPath: "value")
animation.fromValue = beginState
animation.toValue = 1
animation.removedOnCompletion = true
sliderView.layer.addAnimation(animation, forKey: "slider.animation.value")
return
}
}
I'm doing it with new XCode 7.0.1 with iOS target 8.1 In both result ends without animation. UISlider have User interaction disabled. I'm using UISluder because I have custom graphics for slider path min & max track and for the slider thumb.
I did third test
sliderView.setValue(beginState, animated: false)
CATransaction.begin()
CATransaction.setAnimationDuration(duration)
sliderView.setValue(1, animated: true)
CATransaction.commit()
it wont work :/
Summary: Only UIView.animation works. It's animating but it's breaking my customs graphic for UISlider and it's not setting start value for slider.
How can I animate UISlider value change in Todays extension??