Search code examples
objective-ctrackinguislideruitouchcgrect

ContinueTrackingWithTouch:withEvent: method is not being called?


I have a custom UIView class. Inside that view, there is an image view. (I'm making a UISlider from scratch).

I am trying to get the image view -- the thumb of the slider -- to move across the view. Below is the code from the UIView class

- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {

    CGPoint touchPoint = [touch locationInView:self];


    if ( CGRectContainsPoint(self.thumb.frame, touchPoint))

        self.thumb.center = CGPointMake(touchPoint.x, self.thumb.center.y);

    return YES;

}

When I place my finger on the thumb of the slider and try to drag it, nothing happens. However, when I touch outside the thumb of the slider, drag my finger to the thumb without letting go, and then try dragging the thumb, it works fine.

How can I modify my code so that the method will be called when someone holds the thumb and tries to drag it?


Solution

  • My guess is that you have user interaction enabled on your image view, which is in turn not relaying the touch events to the backing logic view. Do something like this:

    self.thumb.userInteractionEnabled = NO
    

    Put that in whatever init method you are using and the thumb view will not interrupt the touch events anymore.