CaliCastle / PopMenu

A fully customizable popup style menu for iOS 😎

Home Page:https://popmenu.cali.so

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How Can I set the menu offset the sourceView

deepindo opened this issue Β· comments

βœ”οΈ Issue Checklist

✍🏻 Issue Description

How can I let the menu below the action button when the menu display. Now it have cover the button. Can you suggest some method? Thx!

πŸ’» Environment

  • iOS Version: [iOS 12]
  • Xcode Version: [XCODE 10]
  • Device(s): [iPhone 8 plus]
  • Simulator?: [NO]

I don't see an easy way to workaround it just yet, that should be a nice feature to have.

I'll add this to the todo list, thanks!

I'd also like this feature. Ideally it would display a bit more like a popup menu with a small arrow pointing to the source button. Right now the PopMenu feels very disconnected from the origin button when using sourceView. Thanks!

Excellent idea. I am still looking for good popup menu but I have to use it with UICollectionViewCell and would like popup to be shown near the cell. Probably adding something like "source" to show near that view will be great!

Slightly unrelated, but here's an extension I use to show pop-up as a result of a gesture on a view (For example: long press on a UICollectionViewCell):

extension PopMenuManager {
    func present(with gesture: UIGestureRecognizer, on viewController: UIViewController, animated: Bool = true, completion: (() -> UIView?)? = nil) {
        let sourceView = UIView(frame: CGRect(origin: gesture.location(in: nil), size: .zero))
        UIApplication.shared.keyWindow?.addSubview(sourceView)
        present(sourceView: sourceView, on: viewController, animated: animated) {
            sourceView.removeFromSuperview()
        }
    }
}

Similar technique can be used to translate the source frame.
Having an option to provide source point or frame would be sweet of course πŸ‘

@raxityo thank you for providing this great example of an extension for PopMenuManager, yeah these things are definitely coming in the next update, I'll be working on these improvements soon and thanks again for the amazing feedback and support!

I'd like to share may solution too !

extension PopMenuManager {

    public func present(
        navItem: UINavigationItem,  // navigationItem.rightBarButtonItem
        on viewController: UIViewController? = nil,
        animated: Bool = true,
        completion: (() -> Void)? = nil) {

        guard let button = navItem.value(forKey: "view") as? UIView else {
            present(sourceView: nil, on: viewController, animated: animated, completion: completion)
            return
        }

        let absFrame = button.convert(button.frame, to: nil)
        let newOrigin = CGPoint(x: absFrame.origin.x, y: absFrame.origin.y + absFrame.height)

        let sourceView = UIView(frame: CGRect(origin: newOrigin, size: .zero))
        UIApplication.shared.keyWindow?.addSubview(sourceView)

        present(sourceView: sourceView, on: viewController, animated: animated) {
            sourceView.removeFromSuperview()
            completion?()
        }
    }
}

The will allow the menu appear below the button of navigationItem.rightBarButtonItem :)

Setting an Offset would be very very useful.

Slightly unrelated, but here's an extension I use to show pop-up as a result of a gesture on a view (For example: long press on a UICollectionViewCell):

extension PopMenuManager {
    func present(with gesture: UIGestureRecognizer, on viewController: UIViewController, animated: Bool = true, completion: (() -> UIView?)? = nil) {
        let sourceView = UIView(frame: CGRect(origin: gesture.location(in: nil), size: .zero))
        UIApplication.shared.keyWindow?.addSubview(sourceView)
        present(sourceView: sourceView, on: viewController, animated: animated) {
            sourceView.removeFromSuperview()
        }
    }
}

Similar technique can be used to translate the source frame.
Having an option to provide source point or frame would be sweet of course πŸ‘

Thank you very much , i managed to show menu at location where user taps by modify your answer a bit, i will share it just incase

             // let location = (location from guesture)

                let sourceView = UIView(frame: CGRect(origin: location, size: .zero))

                view.addSubview(sourceView)

                manager.present(sourceView: sourceView, on: self, animated: true) {

                    sourceView.removeFromSuperview()

                }
            }