Search code examples
iosanimationuislider

How to set same speed to UIView animation


I want to set speed to my UISlider, to make it move more smoothly.

Here is how I am trying to animate it :

 UIView.animateWithDuration(6, delay: 0.0, options: UIViewAnimationOptions.TransitionCurlUp, animations: { () -> Void in

            self.videoSlider.setValue(time, animated: true)
            if self.videoSlider.value == self.videoSlider.maximumValue {
                self.playerLayer.stop()
                self.playBigButton.hidden = false
                self.pauseButton.hidden = true
                self.playButton.hidden = false
            }

            }, completion: { (finished: Bool) -> Void in

        })

But it moves with a different speed on the beginning, middle and end.


Solution

  • Try giving your animation the option of .CurveLinear, like this:

     UIView.animateWithDuration(6, 
                          delay: 0.0, 
                        options: [UIViewAnimationOptions.TransitionCurlUp, .CurveLinear],
                      animations: { () -> Void in
    
                self.videoSlider.setValue(time, animated: true)
                if self.videoSlider.value == self.videoSlider.maximumValue {
                    self.playerLayer.stop()
                    self.playBigButton.hidden = false
                    self.pauseButton.hidden = true
                    self.playButton.hidden = false
                }
    
                }, completion: { (finished: Bool) -> Void in
    
            })