Screen location of NSToolbarItem
How can I get the on-screen location of a button in a toolbar? That is getting the rectangle frame of an NSToolbarItem
? The [NSToolbarItem view]
method seems to always return nil
whenever the toolbar item is only a simple action button and thus I couldn't use the normal NSView
methods to pinpoint the toolbar button's on-screen position.
Background
I'm trying to use Matt Gemmell's MAAtt开发者_运维知识库achedWindow
component to point to a specific toolbar button. The component requires an NSPoint
object to "point" the user to a location on the screen.
Thanks in advance.
I happened to have the same kind of problem. Although I wouldn't say I solved it, I found a way that at least works for my scenario... In my ToolbarItem action I fetch the current mouse location - it proved to be sufficient in this case. An example implementation might look like this:
- (IBAction)showOverlay:(id)sender {
NSPoint clickedPoint = [self.window mouseLocationOutsideOfEventStream];
self.overlayController = [[MyOverlayController alloc] initAtPoint:clickedPoint];
}
精彩评论