1

I need to handle specific action for UITouchTypeStylus touch event and have specific action for button in view.

If i click button with apple pencil both event is triggered.

let me know,how to trigger only UITouchTypeStylus touch event when click button with apple pencil ? or how to handle if we touch buttons or any of actions.. when even it’s stylus.

PrasathBabu
  • 4,716
  • 4
  • 19
  • 35

2 Answers2

1

The best way would be a UIButton subclass with overwritten touchesBegan/Moved/Ended methods and blocks or delegate methods to call passing the touch type. Then check the touch type and invoke the appropriate functionality.

robbdimitrov
  • 149
  • 3
  • 12
0
(void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
{
    UITouch* touch = [touches anyObject];
    if ([touch type] == UITouchTypeStylus)
    {
        //your code...
    }
    else
    {
        return;
    }
    [super touchesBegan: touches withEvent: event];
}
Jacob
  • 43
  • 8
  • **From review queue:** May I request you to please add some context around your source-code. Code-only answers are difficult to understand. It will help the asker and future readers both if you can add more information in your post. – HDJEMAI May 27 '17 at 03:00