How to enable “tap and slide” in a UISlider?

后端 未结 14 567
不知归路
不知归路 2020-12-03 20:54

What I want to get is a UISlider which lets the user not only slide when he starts on its thumbRect, but also when he taps elsewhere. When the user

14条回答
  •  爱一瞬间的悲伤
    2020-12-03 21:39

    My solution is quite simple:

    class CustomSlider: UISlider {
        override func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
            let newValue = 
            self.setValue(newValue, animated: false)
            super.sendActions(for: UIControlEvents.valueChanged)
            return true
    }}
    

提交回复
热议问题