Search code examples
swiftuislider

UISlider glitch shows two thumbs?


A UISlider in my app sometimes shows a second thumb after it is dragged. This is completely unintentional and unwanted. I've done some searching and can't find any other references to this phenomenon. Can anyone figure out why this is happening? Is this a bug?

Two thumb slider:

enter image description here

This code is executed when a "show options" button is pressed:

    readAndApplySettings()  //This sets GameSpeed from a file
    var SpeedSlider = UISlider()
    SpeedSlider.minimumValue = 1
    SpeedSlider.maximumValue = 20       
    SpeedSlider.setValue(Float(21 - GameState.GameSpeed), animated: true)
    SpeedSlider.continuous = true
    SpeedSlider.addTarget(self, action: "SpeedSliderValueDidChange:", forControlEvents: .ValueChanged)
    // Code setting frame and location omitted
    OptionsLabelButton.addSubview(SpeedSlider)

This is the ValueDidChange code:

func SpeedSliderValueDidChange(sender:UISlider) {
    GameState.GameSpeed = Int(21 - sender.value)
    TimerInterval = Double(GameState.GameSpeed) * 0.0167
    tempSpeedLabel.text = "Speed: \(21 - GameState.GameSpeed)"
}

Solution

  • Looks like you have created multiple UISliders, double check you are not calling your function twice. As well, if you are using storyboard to create the UISliders. Make sure you do not have two sliders on top of each other.