在 OSX 上的 Web 视图中显示的 Google 地图顶部绘制子视图

发布于 2024-12-21 09:21:10 字数 949 浏览 2 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若无相欠,怎会相见 2024-12-28 09:21:10

尝试在视图和超级视图上设置[view setWantsLayer:YES]
这可能有帮助。

一个小注释,为什么这有帮助:

Cocoa 文档说:

出于性能原因,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:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文