Long press context menu (like in Pintrest for iOS app)
- iOS 11.0+
- Xcode 9.3+
The easiest way is through CocoaPods. Simply add the dependency to your Podfile
and then pod install
:
pod `GNAContextMenu`
Or Carthage. Add the depdency to your Cartfile
and then carthage update
:
github "gridNA/GNAContextMenu"
import GNAContextMenu
- add on view in
UIViewController
, where you plan to use context menu
UILongPressGestureRecognizer
- create GNAMenuView and set delegate
var menuView = GNAMenuView(menuItems:
[GNAMenuItem(icon: UIImage(named: "shopingCart_inactive"),
activeIcon: UIImage(named: "shopingCart"),
title: "Shop it"),
GNAMenuItem(icon: UIImage(named: "wishlist_inacitve"),
activeIcon: UIImage(named: "wishlist"),
title: "Wish")])
menuView.delegate = self
- on long press
menuView.handleGesture(gesture, inView: yourView)
You can also implement GNAMenuItemDelegate methods:
menuItemWasPressed(menuItem: GNAMenuItem, info: [String: AnyObject]?)
menuItemActivated(menuItem: GNAMenuItem, info: [String: AnyObject]?)
menuItemDeactivated(menuItem: GNAMenuItem, info: [String: AnyObject]?)
Please see example for more info.