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

后端 未结 15 1631
被撕碎了的回忆
被撕碎了的回忆 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 13:01

    Note: this no longer works as of iOS 11

    In lieu of that mess with trying to find the UIBarButtonItem's view in the toolbar's subview list, you can also try this, once the item is added to the toolbar:

    [barButtonItem valueForKey:@"view"];
    

    This uses the Key-Value Coding framework to access the UIBarButtonItem's private _view variable, where it keeps the view it created.

    Granted, I don't know where this falls in terms of Apple's private API thing (this is public method used to access a private variable of a public class - not like accessing private frameworks to make fancy Apple-only effects or anything), but it does work, and rather painlessly.

提交回复
热议问题