PopMenu icon indicating copy to clipboard operation
PopMenu copied to clipboard

How Can I set the menu offset the sourceView

Open deepindo opened this issue 7 years ago • 8 comments
trafficstars

✔️ 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]

deepindo avatar Sep 20 '18 05:09 deepindo

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!

CaliCastle avatar Sep 20 '18 05:09 CaliCastle

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!

kfound avatar Oct 07 '18 00:10 kfound

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!

XRayAdamo avatar Oct 18 '18 17:10 XRayAdamo

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 avatar Oct 23 '18 01:10 raxityo

@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!

CaliCastle avatar Oct 23 '18 18:10 CaliCastle

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 :)

zhongxinghong avatar Aug 07 '19 09:08 zhongxinghong

Setting an Offset would be very very useful.

omarojo avatar Nov 20 '20 03:11 omarojo

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

                }
            }

m7mdra avatar Jun 24 '21 21:06 m7mdra