-
Notifications
You must be signed in to change notification settings - Fork 186
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
Comments
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 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. |
@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 |
Setting an Offset would be very very useful. |
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()
}
} |
✔️ 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
The text was updated successfully, but these errors were encountered: