Is there a way to programmatically show a UIMenu
on iOS on a double-tap event?
I have an app that's been around for over a decade, so there are some UX patterns that I'm reluctant to mess around with.
There is a view in my app with the following properties:
- Tapping the view once focuses it and brings it to the front
- Double-tapping it shows a view controller as a sheet, with several operations you can perform on that object
Instead of the sheet, I'd like to move to context menus - they look better, and they're more familiar for users. Obviously, adding a context menu for long-press is straightforward (just use UIContextMenuInteraction
). But there does not seem to be a way to show the context menu on double-tap.
I've discovered that you can use UIButton
with showsMenuAsPrimaryAction
to show the menu on single-tap, but that doesn't quite work for me. My users expect a single tap to do something else (focus the view) and will be annoyed if single taps start showing menus instead.
So, is there a way to show a context menu on double tap in iOS?
There isn't a facility to show the menu on double tap directly. UIControl allows you to build both single tap and long press experiences with menus.
While it isn't quite what your looking for, you could build a UIControl subclass where the menu is only enabled when the control is "focused", thus emulating the experience you already have (first tap would focus, then enable the menu, 2nd tap would show the menu).