Hi, I've been trying to set the slider value in the same direction with finger drag movement on the screen. From right to left, decrease the slider value and vice versa. I have set up the slider outlet and the UIPanGestureRecognizer. I'm having trouble with assigning the slider thumbRect on "addPanGesture(slider: UISlider)" method when I call it. If I assign the slider, the whole slider starts moving. I'm aiming to move the thumbRect in accordance with the UIPanGestureRecognizer. I'm sharing the relevant code. In case, you need the whole code, I'd be more than happy to share it with you. Any suggestion please ?
class PhotoViewController: UIViewController {
@IBOutlet weak var effectsSlider: UISlider!
var initialCenter: CGPoint!
override func viewDidLoad() {
super.viewDidLoad()
initialCenter = effectsSlider.frame.origin
}
func addPanGesture(slider: UISlider) {
let pan = UIPanGestureRecognizer(target: self, action: #selector(PhotoViewController.handlePan(sender:)))
view.addGestureRecognizer(pan)
}
@objc func handlePan(sender: UIPanGestureRecognizer) {
let panView = sender.view!
let translation = sender.translation(in: view)
switch sender.state {
case .began, .changed:
panView.center = CGPoint(x: panView.center.x + translation.x, y: panView.center.y + translation.y)
sender.setTranslation(CGPoint.zero, in: view)
case .ended:
return
default:
break
}
}
}