Вопрос

I want to attach a WebView to the cursor when the user hovers a button. And remove it when the mouse exits.
Even when the cursor moves inside the button I want to WebView to keep following the cursor.
Any ideas on how to perform this?

Here's an example on how it should be:
enter image description here

Это было полезно?

Решение

so you have a NSButton ... subclass THAT so you attach a view:

@interface ButtonWithWebViewOnHover : NSButton
@property(strong) WebView *webView;
@end

override mouseEntered and mouseExited there and toggle hidden

...... wait.... we seem to be reinventing the wheel


use NSPopover (from apple directly, but not as graphically flexible as the next:)

or MAAttachedWindow (http://mattgemmell.com/2007/10/03/maattachedwindow-nswindow-subclass/)

Другие советы

You can subclass WebView, and consider that to draw it this method is called:

- (void)drawRect:(NSRect)dirtyRect;

Ao if you call [super drawInRect: dirctyRect] in this method, the view will be normally drawn, otherwise nothing will be drawn.So you can see if the mouse is over the view and decide if to draw it or not.

To resize it, instead you can use this method:

- (void)setBounds:(NSRect)boundsRect;

To detect mouse events you shall implement methods like mouseDown (see NSResponder) in your main view.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top