8

I'm using a context menu in my catalyst app by using

let interaction = UIContextMenuInteraction(delegate: self)
editButton.addInteraction(interaction)

This works fine on Mac and menu is opened when user clicked by using right mouse button.

On the other hand, I need to open the same menu on a normal button click on some cases especially if the user is using the app on iPad. Is there any way to open the same context menu on normal button click/tap event?

Cœur
  • 37,241
  • 25
  • 195
  • 267
emreoktem
  • 2,409
  • 20
  • 36
  • What's wrong with default behaviour on 3D Touch, and long-press gestures? – Asperi Jan 22 '20 at 16:09
  • On catalyst app, I need to open the menu by normal tap especially on mac version of the app. 3D touch is not always available on Macs – emreoktem Jan 27 '20 at 09:35

1 Answers1

1

Well, official documentation clearly states that UIContextMenuInteraction handles user interaction by itself, so there is no official way to change this, at least for now - we provide only content, everything else is behind the scene.

From developer.apple.com

Declaration

class UIContextMenuInteraction : NSObject

Overview

Use a UIContextMenuInteraction object to focus the user's attention on a specific portion of your content, and to provide actions for the user to perform on that content. A context menu interaction object tracks Force Touch gestures on devices that support 3D Touch, and long-press gestures on devices that don't support it. When the appropriate gesture occurs, this object animates your content to a new interface and displays the contextual menu that you supplied. UIKit manages all menu-related interactions and reports the selected action, if any, back to your app.

Asperi
  • 228,894
  • 20
  • 464
  • 690