1

In my view I have in the right part 3 UISlider and in the left part the user can slide the menu with a UIPanGestureRecognizer. Sometimes, when the user uses the slider, it also drag the view. I don't want this to happen. I have this code in my panLayer method:

- (IBAction)panLayer:(UIPanGestureRecognizer *)pan {

if (pan.state == UIGestureRecognizerStateChanged) {
    CGPoint point= [pan translationInView:self.topLayer];
    CGRect frame = self.topLayer.frame;
    frame.origin.x = MIN(258.0f, self.layerPosition + point.x);
    if (frame.origin.x < 0) frame.origin.x = 0;
    self.topLayer.frame = frame;
 }
if (pan.state == UIGestureRecognizerStateEnded) {
    if (self.topLayer.frame.origin.x <=160) {
        [self animateLayerToPoint:0];
    }
    else {
        [self animateLayerToPoint:VIEW_HIDDEN];
    }
 }


}

I want to create an if statement with the x position. Something like this:

if (firstTouch.x < 150 && firstTouch.x > 0) {
   //Add my previous code
}

How can I access to the firstTouch in the view, and if it is in this area, run the UIPanGestureRecognizer?

Thanks

4

1 回答 1

2

This can be easily achieved by adopting UIGestureRecognizerDelegate and implementing the following method:

-(BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(UITouch*)touch
{
    return touch.view != myUISlider;
}
于 2013-05-11T13:14:21.460 回答