I'm opening a NSPopover
with the action of an icon in the status bar.
myPopover.show(relativeTo: button.bounds, of: button, preferredEdge: NSRectEdge.minY)
This works fine with the exception that the distance from the popover and the system bar is zero:
I'd like to achieve the same result as the Dropbox app which renders the popover at a small distance from the system bar:
I've tried using button.bounds.offsetBy(dx: 0.0, dy: 20.0)
which doesn't affect the position of the popover and button.bounds.offsetBy(dx: 0.0, dy: -20.0)
which puts the popover above the system bar:
So how can I position the NSPopover
at some distance from the system bar?
First, the reason why
button.bounds.offsetBy(dx: 0.0, dy: -20.0)
didn't work is because those coordinate fell outside the "window" of the status bar item which is the status bar itself. So anything outside of it was cropped.I solved this problem by collecting information here and there:
NSPopover
in relation to the invisible window and not the status bar item.The red thing is the invisible window (for demonstration purposes).
Swift 4 (Xcode 9.2)
I was trying to use
show(relativeTo: invisibleWindow.frame ...)
and the popup wasn't showing up becauseNSWindow
is not anNSView
. For the popup to be displayed a view has to be passed.