Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catalyst - Opening context menu programmatically

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?

like image 897
emreoktem Avatar asked Jan 19 '20 11:01

emreoktem


1 Answers

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.

like image 50
Asperi Avatar answered Oct 06 '22 12:10

Asperi