GNAContextMenu
长按上下文菜单(例如 iOS 应用 Pinterest 中的菜单)
需求
- iOS 11.0+
- Xcode 9.3+
安装
最简单的方式是通过 CocoaPods。只需将依赖项添加到你的 Podfile
,然后运行 pod install
pod `GNAContextMenu`
或者 Carthage。将依赖项添加到你的 Cartfile
,然后运行 carthage update
github "gridNA/GNAContextMenu"
如何使用
import GNAContextMenu
- 在
UIViewController
的视图中添加上下文菜单,你打算在那里使用上下文菜单
UILongPressGestureRecognizer
- 创建 GNAMenuView 并设置代理
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
- 在长按
menuView.handleGesture(gesture, inView: yourView)
你也可以实现 GNAMenuItemDelegate 方法
menuItemWasPressed(menuItem: GNAMenuItem, info: [String: AnyObject]?)
menuItemActivated(menuItem: GNAMenuItem, info: [String: AnyObject]?)
menuItemDeactivated(menuItem: GNAMenuItem, info: [String: AnyObject]?)
请参阅示例了解更多信息。