All Projects → camelcc → MenuPopOverView

camelcc / MenuPopOverView

Licence: WTFPL license
A custom PopOverView looks like UIMenuController works on iPhone.

Projects that are alternatives of or similar to MenuPopOverView

MenuPopupView
一款仿iOS长按菜单弹窗的自定义控件
Stars: ✭ 26 (-57.38%)
Mutual labels:  uimenucontroller

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].