KActionMenu

Like to iOS 3D touch menu

23
4
Swift

KActionMenu




MIT Licance Pod Tag Swift

Requirements

  • Xcode 9.0 +
  • iOS 11.0 or greater

Installation

CocoaPods

  1. Install CocoaPods
  2. Add this repo to your Podfile
platform :ios, '11.0'

target 'ProjectName' do
  use_frameworks!
  pod 'KActionMenu'
end
  1. Run pod install
  2. Open up the new .xcworkspace that CocoaPods generated
  3. Whenever you want to use the library: import KActionMenu

Manually

  1. Simply download the KActionMenu source files and import them into your project.

Usage

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()
    }
}

License

Usage is provided under the MIT License. See LICENSE for the full details.