Double-Tap Alternative

Instead of implementing the long-tap gesture menu provided by UICollectionView, Recipe 10-9 creates a custom cell class and adds a double-tap gesture recognizer. When activated, the callback sets the cell as the first responder and presents a standard menu.

Recipe 10-9 shows the relevant details. The cell subclass declares that it can become the first responder, a necessary precondition for presenting menus. It sets the menu items it wants to work with and then adds the canPerformAction:withSender: support that confirms each item’s appearance. Figure 10-10 displays the menu created by this code.

Recipe 10-9 Custom Collection View Cell Menus

- (BOOL)canBecomeFirstResponder {     return YES; ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.