Like to iOS 3D touch menu
Podfile
platform :ios, '11.0'
target 'ProjectName' do
use_frameworks!
pod 'KActionMenu'
end
pod install
.xcworkspace
that CocoaPods generatedimport KActionMenu
KActionMenu
source files and import them into your project.import UIKit
class ViewController: UIViewController {
@IBOutlet weak var bgImageView: UIImageView!
var menu:KActionMenu!
override func viewDidLoad() {
super.viewDidLoad()
bgImageView.addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(longPressAction)))
menu = KActionMenu(rootView: self.view) // 1.
menu.view.table.actionDelegate = self
menu.view.screenDelegate = self
menu.setMenuStyle(.light) // .light, .dark
}
@objc func longPressAction(gesture: UILongPressGestureRecognizer) {
let location = gesture.location(in: bgImageView)
menu.show(items: [("Follow", UIImage(named: "add")), ("Camera", UIImage(named: "cam")), ("Share", UIImage(named: "share")), ("Like", UIImage(named: "like"))], position: CGPoint(x: location.x, y: location.y), animation: .scale) // 2.
}
}
extension ViewController: KActionDelegate, KActionScreenDelegate {
func didCloseScreen() {
print(" - Closed - ")
}
func touchItem(name: String, index: Int) {
print(name, index)
self.menu.view.close()
}
}
Usage is provided under the MIT License. See LICENSE for the full details.