0

I am trying to build a custom slider using SpriteKit.

The Scrubber : SKScene class is responsible for creating the slider. The viewDidLoad in my ViewController looks like this

       var scrubber : Scrubber!

override func viewDidLoad() {
    super.viewDidLoad()

 // Create the scrubber 

    if let view = self.spriteView {
        if let scene = Scrubber(fileNamed: "Scrubber") {
            self.scrubber = scene
            scene.scaleMode = .aspectFill
            view.presentScene(scene) }

               } }

It has a thumb sliding left and right along a track, and is setting a value between 0 and 1 and I would like to implement the

addTarget(_:action:for: .valueChanged)          // just like a UISlider

Every time the the thumb slides left or right OR jumps to a position.X the , value changes.

I want to call a method in my ViewController class everytime the value changes.

How can I do this?

NOTE:

  • This question has previously been asked here , but it is in Objective-C , and I couldn't get the solution to work for swift.
  • There is no UIControlEvent in my case .The valueChanged(..) event has to be set up in code explicitly. What I want to know is , how can a target/Action scheme be used in the absence of a UIControl.
Community
  • 1
  • 1
  • 1
    Possible duplicate of [Hooking up UIButton to closure? (Swift, target-action)](http://stackoverflow.com/questions/24962151/hooking-up-uibutton-to-closure-swift-target-action) – David Berry Apr 24 '17 at 23:08
  • My use case is, how to create a _target / action_ scheme , when there is no `UIControlEvent` involved –  Apr 25 '17 at 05:03

0 Answers0