在OSX上的WebView中显示的Google Map顶部绘制子视图 [英] Drawing a Subview on top of a Google Map Displayed in a WebView on OSX

查看:113
本文介绍了在OSX上的WebView中显示的Google Map顶部绘制子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在OSX中创建一个简单的实用程序,在WebView中呈现Google地图,并在其上显示一些视图。对于大多数网站(包括指向maps.google.com的链接),子视图将呈现在WebView的顶部。甜。但是如果我使用Google Maps API v3,由于某种原因,地图内容将呈现在我的子视图上。



下面是一个例子:



我有一个窗口,有两个子视图,一个WebView和一个NSButton。顺序是按钮应该在顶部。



如果我加载

pre> maps.google.com/maps?q=-33.86818,+151.1963

...按钮显示在视图顶部:



http://dl.dropbox.com/u/22329586/1_webviewproblem_works.png



但如果我加载此Google演示

  gmaps-samples-v3.googlecode.com/svn/trunk/draggable-directions/draggable-directions .html 

...它使用Google Map API v3, p>

http://dl.dropbox。 com / u / 22329586 / 2_webviewproblem_doesnt_work.png



(对不起,我没有足够的信誉来内联图片)



尝试设置任何想法?

解决方案 YES]
它可能有帮助。



一个小笔记,为什么这有帮助:



Cocoa docs说:


出于性能原因,Cocoa不强制在同级
视图之间进行剪辑,或者保证正确的无效和绘图行为
兄弟视图重叠。如果你想在
前面绘制视图,你应该使前视图成为后视图的子视图(或后代)




如果您使用NSViews没有启用层支持 setWantsLayer:YES ,并且其中一个视图偶尔层支持或层托管



但是当您在视图中启用图层备份时,它们都会绘制在支持重叠的CALayer层次结构中。


I'm trying to make a simple utility in OSX that renders a Google Map in a WebView and displays some views on top of it. For most websites, including links to maps.google.com, the subviews will render on top of the WebView. Sweet. But if I use the Google Maps API v3, for some reason the map content will render over my subviews.

Here's an example:

I have a window with two subviews, a WebView, and an NSButton. The order is such that the button should be on top. I placed the button so half of it is over the WebView to make the example clearer.

If I load up

maps.google.com/maps?q=-33.86818,+151.1963

... the button appears on top of the view:

http://dl.dropbox.com/u/22329586/1_webviewproblem_works.png

But if I load up this google demo

gmaps-samples-v3.googlecode.com/svn/trunk/draggable-directions/draggable-directions.html

...which uses the Google Map API v3, it renders over the content:

http://dl.dropbox.com/u/22329586/2_webviewproblem_doesnt_work.png

(Sorry, I don't enough reputation points to post the images inline)

Any ideas?

解决方案

try to set [view setWantsLayer:YES] on both views and superview. It may help.

a small note, why that helps:

Cocoa docs says:

For performance reasons, Cocoa does not enforce clipping among sibling views or guarantee correct invalidation and drawing behavior when sibling views overlap. If you want a view to be drawn in front of another view, you should make the front view a subview (or descendant) of the rear view.

if you use NSViews without layer backing enabled setWantsLayer:YES, and one of the views is occasionally layer backing or layer hosting or OpenGL view, it will be drawn over all others.

but when you enable layer backing in views, they all are drawn in CALayer hierarchy that supports overlapping.

这篇关于在OSX上的WebView中显示的Google Map顶部绘制子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆