3

This is the code of my CustomUIGestureRecognizer.m

@implementation CustomTapGestureRecognizer

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(_customDelegate != nil && [_customDelegate respondsToSelector:@selector(onTouchDown:)])
    {
        [_customDelegate onTouchDown:self];
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(_customDelegate != nil && [_customDelegate respondsToSelector:@selector(onTouchUp:)])
    {
        [_customDelegate onTouchUp:self];
    }
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"cancelled");
}

@end

As can be seen from the code above, I can only detect "touch down" and "touch up" events. But, I need to detect "touch up inside" control event.

I tried to check if the touches cancelled would be triggered when I lift my finger outside the view, this way I would be able to know whether the touch up was inside or not. Unfortunately, it was not called.

Any ideas? Thanks!

JLT
  • 3,052
  • 9
  • 39
  • 86
  • you have gesturerecognizer.view property. so you can calculate touch coordinates and view coordinates to find yourself whether the touch is within view frame or not – Shubhank May 11 '16 at 12:22
  • @Shubhank Hey, thanks! But aside from this, is there an easier way, like using the UIEvent object returned from touchesEnd? – JLT May 11 '16 at 13:01
  • dont know, sorry. +1 to the ques – Shubhank May 11 '16 at 13:06
  • @Shubhank Alright, thanks!. – JLT May 11 '16 at 13:14
  • I know this is an old question, but I found an answer that helped me [here](https://stackoverflow.com/a/43512974/4905076) – Lucho Feb 02 '18 at 19:46

0 Answers0