Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How Can I set the menu offset the sourceView #14

Open
4 tasks done
deepindo opened this issue Sep 20, 2018 · 8 comments
Open
4 tasks done

How Can I set the menu offset the sourceView #14

deepindo opened this issue Sep 20, 2018 · 8 comments
Assignees
Labels
enhancement New feature or request
Projects

Comments

@deepindo
Copy link

✔️ 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]
@CaliCastle CaliCastle self-assigned this Sep 20, 2018
@CaliCastle CaliCastle added the enhancement New feature or request label Sep 20, 2018
@CaliCastle
Copy link
Owner

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!

@kfound
Copy link

kfound commented Oct 7, 2018

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!

@CaliCastle CaliCastle added this to To do in v2.2.0 via automation Oct 7, 2018
@XRayAdamo
Copy link

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!

@raxityo
Copy link

raxityo commented Oct 23, 2018

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 👍

@CaliCastle
Copy link
Owner

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

@zhongxinghong
Copy link

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

@omarojo
Copy link

omarojo commented Nov 20, 2020

Setting an Offset would be very very useful.

@m7mdra
Copy link

m7mdra commented Jun 24, 2021

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

                }
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
v2.2.0
  
In progress
Development

No branches or pull requests

8 participants