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 .ThevalueChanged(..)
event has to be set up in code explicitly. What I want to know is , how can atarget/Action
scheme be used in the absence of aUIControl
.