webview in core animation layer
The only other thread I can find is the above which doesn't necessarily fit my needs. Is there a reliable way to simply draw a view on top of a webview? I've tried to layer a regular NSView on top of WebView, and it draws right at first, but any movement in the webview (scrolling the page etc) appears to invalidate the view and produces visual artifacts.
I've tried:
[[[NSApp mainWindow] contentView] addSubview:view positioned:NSWindowAbove relativeTo:webView];
No luck there, same problems -- z-ordering doesn't seem to work unless I'm missing something.
Is this just a limitation of webviews?
I also tried implementing the view above as a window, which worked much better (just controlled the location of the window programmatically). However, the desired behavior is for the user to enter some text into this window, but for it not to steal "focus" -- ie the main window goes inactive (the x - + go gray) when the user clicks on the text field in the new window. Any way to avoid that?
I've tried subclassing NSWindow and overriding canBecomeKey (return YES) and canBecomeMain (return NO) but the window still steals focus.
EDIT: I weep :-( I can't figure out a way around the drawing over webkit thing. I did, on the other hand, figure out a way to force the main window of my app to retain active state even though you have a popup window with key state. However, it has unintended consequences when using the text input on the popup dialog (which has to be forced into the key window state). Backspace doesn't work :: shakes head ::, and mouse events are not getting distributed to the webkit views below (for mouseovers on components embedded in the html). Craptacular.
Josh
A bit late, but I banged my head at the same problem and two years after the question I still couldn't find the answer. In my case, setting wantsLayer=YES on the view I wanted to draw over the WebView solved the problem.
来源:https://stackoverflow.com/questions/2861117/layering-cocoa-webview-drawing-on-top