Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
You can simplify interactions with your app using context menus in Swift, Home Screen quick actions, and keyboard shortcuts.
Today, we will learn how we can add context menus in Swift.
An object UIContextMenuInteraction is used to get the user action.
UIContextMenuInteraction tracks the long press gesture and animates the content and displays the contextual menu provided by you.
The UIContextMenuInteraction is inherited from the UIInteraction protocol, which in turn inherits from NSObjectProtocol. We need to conform to the protocol in order to use its functions.
Such as, addInteraction(_:) function is used to add interaction to that particular view.
Please visit here for more references.
Here is a piece of code that adds a context menu to a view.
We have created a button that when clicked shows the context menus.
The menuItems variable returns an array of elements of type UIAction.
UIAction is responsible for handling the actions performed on the menu items, so we can write our code inside the handler block.
The demoMenu creates UIMenu objects and uses them to construct the menus.
When the user selects an element from the menu, the system executes the code that we provide.
Finally, call the UIMenu as below.
On clicking on the showAction button a pop-over is presented on the screen with the menus as defined in menuItems variable.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Great Product, Great Team, and Great Support Service. And if you want to add more features to the product, they can submit any idea that comes to your mind. They really care about their clients and we are really happy and honored to deal with Webkul.
Osama
USA
India
Global
Name
Email
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.