0

What I'm doing works on both the simulator and my iPad2, I'm not having problems with it, but it is not the documented way to do things so I'm worried it might not work on newer iPads.

I have UIButtons where I distinguish between a touch and a long press.

The buttons are constructed as usual, with a target and action, no gestures.

- (IBAction)buttonAction:(id)sender forEvent:(UIEvent*)event
{
  UIButton *button=(UIButton *)sender;

  bool longpress=NO;
  UITouch *touch=[[[event allTouches] allObjects] objectAtIndex:0];
  if(touch.tapCount==0) longpress=YES;

  switch(button.tag)
  {
    case TAG:
    {
        if(longpress)
        {
              ... do longpress thing
        }
        else
        {
              ... do regular touch thing
        }
        break;
    }
    ...
  }
}

1 Answer 1

0

Why don't you create a UILongPressGestureRecognizer and add it to the button. This is the preferred way to recognise such actions.

1
  • What I'm doing works, and the code is simple. I was wondering if it works for everyone, or if anyone else has done this. Aug 5, 2014 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.