在 OSX 上的 Web 视图中显示的 Google 地图顶部绘制子视图
我正在尝试在 OSX 中创建一个简单的实用程序,在 WebView 中呈现 Google 地图并在其顶部显示一些视图。对于大多数网站(包括指向maps.google.com 的链接),子视图将呈现在WebView 之上。甜的。但如果我使用 Google Maps API v3,出于某种原因,地图内容将在我的子视图上呈现。
下面是一个示例:
我有一个带有两个子视图、一个 WebView 和一个 NSButton 的窗口。顺序是按钮应位于顶部。我将按钮的一半放置在 WebView 上,以使示例更清晰。
如果我加载
maps.google.com/maps?q=-33.86818,+151.1963
...按钮会出现在视图顶部:
http://dl .dropbox.com/u/22329586/1_webviewproblem_works.png
但是如果我加载这个
gmaps-samples-v3.googlecode.com/svn/trunk/draggable-directions/draggable-directions.html
使用 Google Map API v3 的 Google 演示,它会渲染内容:
http://dl.dropbox.com/u/22329586/2_webviewproblem_doesnt_work.png< /a>
(抱歉,我没有足够的声誉点来内嵌发布图像)
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在视图和超级视图上设置
[view setWantsLayer:YES]
。这可能有帮助。
一个小注释,为什么这有帮助:
Cocoa 文档说:
如果您使用未启用图层支持的 NSViews
setWantsLayer:YES
,并且其中一个视图偶尔是图层支持或图层托管或 OpenGL 视图,则它将绘制在所有其他视图之上。但是当您在视图中启用图层支持时,它们都会在支持重叠的 CALayer 层次结构中绘制。
try to set
[view setWantsLayer:YES]
on both views and superview.It may help.
a small note, why that helps:
Cocoa docs says:
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.