透明 NSImageView 落后于 NSView

发布于 2024-10-17 07:28:56 字数 705 浏览 11 评论 0原文

我有一个透明的 .png 图像,位于 NSView 上,它应该如下所示:

在此处输入图像描述

然而,有时,在没有任何押韵或原因或迹象表明它将执行此操作的情况下,NSImageView 落后于 NSView

在此处输入图像描述

我不知道如何将 NSImageView 保持在 之上NSView,或者为什么它甚至落后于 NSView

这是 Interface Builder 中的样子: 在此处输入图像描述

更新:

我已尝试以下方法,但结果相同:

[header removeFromSuperview];
[mainView addSubview:header positioned:NSWindowAbove relativeTo:nil];

实现此目的的更好方法是什么效果如何?

I have a transparent .png image that lays over an NSView and it should look like this:

enter image description here

However, sometimes, with no rhyme or reason or indication that it is going to do this, the NSImageView falls behind the NSView:

enter image description here

I am not sure how to keep the NSImageView above the NSView, or why it even falls behind the NSView.

Here is what it looks like in Interface Builder:
enter image description here

Update:

I have tried the following with same results:

[header removeFromSuperview];
[mainView addSubview:header positioned:NSWindowAbove relativeTo:nil];

What is a better way to achieve this effect?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

紫罗兰の梦幻 2024-10-24 07:28:56

重叠的 Cocoa UI 元素具有未定义的绘制顺序,Apple 声明您不应重叠它们。您可以创建一些自定义绘图代码来使当前的设计正常工作。然而,说实话,我会改变设计,使其符合 Mac OS X 的人机界面指南。您可以通过下面的链接阅读有关这些内容的信息。
http://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AppleHIGuidelines/XHIGIntro/XHIGIntro.html%23//apple_ref/doc/uid/TP30000894-TP6

Cocoa UI elements that overlap have an undefined drawing order, and Apple states that you shouldn't overlap them. You could create some custom drawing code to make your current design work. However, honestly I would change the design so it matches with Mac OS X's human interface guidelines. You can read about these at the link below.
http://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AppleHIGuidelines/XHIGIntro/XHIGIntro.html%23//apple_ref/doc/uid/TP30000894-TP6

七秒鱼° 2024-10-24 07:28:56

当您在同一级别上有两个重叠的 NSView 时,未定义绘制顺序。您可以使用 SubviewsUsingFunction:context: 对子视图的绘制进行排序。您必须提供一个比较函数,根据某个值(例如标签)进行比较:

NSComparisonResult viewCompareByTag(NSView *firstView, NSView *secondView, void *context) {
    return ([firstView tag] > [secondView tag]) ? NSOrderedAscending : NSOrderedDescending;
}

[mySuperView sortSubviewsUsingFunction:&viewCompareByTag context:nil];

When you have two overlapping NSView on the same level it is undefined what the drawing order will be. You can sort the drawing of the subviews using SubviewsUsingFunction:context:. You'll have to provide a comparison function that compares based on some value (e.g. tag):

NSComparisonResult viewCompareByTag(NSView *firstView, NSView *secondView, void *context) {
    return ([firstView tag] > [secondView tag]) ? NSOrderedAscending : NSOrderedDescending;
}

[mySuperView sortSubviewsUsingFunction:&viewCompareByTag context:nil];
北恋 2024-10-24 07:28:56

结果我不得不重新排列 Interface Builder 中的一些视图,
然后在代码中:

[[header layer] setZPosition:1.0f];

Turns out that I had to re-arrange some of the views in Interface Builder,
then in code:

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