3

I have a video player slider, I want to track event when user has started sliding video player slider and ended sliding video player slider. Also, I am tracking what slider value have changed. When slider starts and its value get changed I am able to track it successfully. My problem is when sliding ends I am not able to track it. Which UIControlEvent should I use for sliderEndedTracking?

I am using the following code:

// Slider actions for UIControlEvents
        playerSlider.addTarget(self, action: #selector(sliderBeganTracking(_:)),
            forControlEvents: UIControlEvents.TouchDown)
        playerSlider.addTarget(self, action: #selector(sliderEndedTracking(_:)),
            forControlEvents: UIControlEvents.TouchUpInside )
        playerSlider.addTarget(self, action: #selector(sliderEndedTracking(_:)),
            forControlEvents: UIControlEvents.TouchUpOutside)
        playerSlider.addTarget(self, action: #selector(sliderValueChanged(_:)),
            forControlEvents: UIControlEvents.ValueChanged)


// Slider Actions:
        func sliderBeganTracking(slider: UISlider!) {
            Log.Debug("sliderBeganTracking")
        }

        func sliderEndedTracking(slider: UISlider!) {
            Log.Debug("sliderEndedTracking")
        }

        func sliderValueChanged(slider: UISlider!) {
            Log.Debug("sliderValueChanged")
        }
AnthoPak
  • 4,191
  • 3
  • 23
  • 41
Ashish Verma
  • 1,776
  • 1
  • 16
  • 27

2 Answers2

7

First of all you need to do CNTRL+DRG from UISlider(Storyboard) to your view controller. Here, Use 'Value Changed' Event.

At this action you try any code just print something.

Secondly, Make outlet of UISlider as slider. than use following code ::

 self.slider.addTarget(self, action: #selector(PreviewViewController1.sliderDidEndSliding(_:)), forControlEvents: ([.TouchUpInside,.TouchUpOutside]))

Try to print something now in sliderDidEndSliding() Method. Example :

func sliderDidEndSliding(notification: NSNotification)
    {
print("Hello")
}

By using these two methods you will get the actual prior implementation of UISlider.

JAck
  • 854
  • 9
  • 18
  • 1
    Thank you so much. I started the search for this answer hours ago. Yours is the only thing that's worked for my Swift3 project. I had to modify slightly: radSlider.addTarget(self, action: #selector(sliderDidEndSliding(notification:)), for: ([.touchUpInside,.touchUpOutside])) – CptRayMar Jan 21 '17 at 20:11
  • Thank you very much! [.touchUpInside,.touchUpOutside] perfect work for when value DID changed – Booharin Dec 22 '18 at 16:06
1

TouchUpInside event is working for me. If you release finger from UISlider, the event is fired. Isn't what you want ?

AnthoPak
  • 4,191
  • 3
  • 23
  • 41