1

I created a custom slider with UIPanGestureRecognizer. The problem is that the custom slider has lag. See this video: https://vid.me/CtME . I click and drag the custom "3km", but it starts moving only after some distance and not right away. The "1km" UISlider does not have lag. How can I fix that?

code:

thumb = UIImageView(frame: CGRectMake(x, y, width, height))
        thumb.image = UIImage(named: "3km")
        thumb.userInteractionEnabled=true
        backgrounImageView.addSubview(thumb)

        let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: "pan:")
        thumb.addGestureRecognizer(panGestureRecognizer)


func pan(gestureRecognizer:UIPanGestureRecognizer){
        let vv = gestureRecognizer.view
        print((vv?.superview?.frame.width)!)
        print("x: \(gestureRecognizer.locationInView(vv?.superview).x)")
        let x = gestureRecognizer.locationInView(vv?.superview).x

        if (x < (vv?.superview?.frame.width)!*0.11 || x > (vv?.superview?.frame.width)!*0.89){
            return
        }


        switch gestureRecognizer.state {

        case .Began, .Changed:
            let delta = gestureRecognizer.translationInView(vv?.superview)
            var c = vv?.center
            c!.x += delta.x
            vv?.center = c!
            gestureRecognizer.setTranslation(CGPointZero, inView: vv?.superview)

        default:
            break

        }
    }
potato
  • 4,479
  • 7
  • 42
  • 99
  • Similar question was answered here: http://stackoverflow.com/questions/10728066/why-is-there-a-delay-when-moving-object-using-uipangesturerecognizer – crisisGriega Feb 25 '16 at 15:49

0 Answers0