How can you add a UIGestureRecognizer to a UIBarButtonItem as in the common undo/redo UIPopoverController scheme on iPad apps?

后端 未结 15 1572
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 12:36

Problem

In my iPad app, I cannot attach a popover to a button bar item only after press-and-hold events. But this seems to be standard for

15条回答
  •  不思量自难忘°
    2020-12-07 12:46

    This is an old question, but it still comes up in google searches, and all of the other answers are overly complicated.

    I have a buttonbar, with buttonbar items, that call an action:forEvent: method when pressed.

    In that method, add these lines:

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

    If it was a single tap, tapCount is one. If it was a double tap, tapCount is two. If it's a long press, tapCount is zero.

提交回复
热议问题