Skip to content
This repository has been archived by the owner on Apr 15, 2022. It is now read-only.
/ MenuPopOverView Public archive

A custom PopOverView looks like UIMenuController works on iPhone.

License

Notifications You must be signed in to change notification settings

camelcc/MenuPopOverView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MenuPopOverView

MenuPopOverView been rewrite in swift. It looks like UIMenuController but can popover from anyview you want.

Install

Carthage:

github "camelcc/MenuPopOverView"

Example

class ViewController: UIViewController {
    var menuPopOverView: MenuPopOverView? = nil

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        self.view.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(tapped(tap:))))
    }

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        menuPopOverView?.dismiss(false)
    }

    @objc private func tapped(tap: UITapGestureRecognizer) {
        let tapLocation = tap.location(in: self.view)
        if menuPopOverView == nil {
            menuPopOverView = MenuPopOverView()
        }
        menuPopOverView?.delegate = self
        menuPopOverView?.present(at: CGRect(x: tapLocation.x, y: tapLocation.y, width: 0, height: 0),
                                in: self.view,
                                with: ["Test1", "TestAAAAAAA", "t", "example", "loooooooooooooooongbutton"])
    }
}

extension ViewController: MenuPopOverViewDelegate {
    func didSelect(view: MenuPopOverView, at index: Int) {
        print("didSelect at \(index)")
    }

    func didDismiss(view: MenuPopOverView) {
        print("didDismiss")
        menuPopOverView = nil
    }
}

popover

License

WTFPL

Support me

Buy me a coffee