透明 NSImageView 落后于 NSView
我有一个透明的 .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:
However, sometimes, with no rhyme or reason or indication that it is going to do this, the NSImageView
falls behind the NSView
:
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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
重叠的 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
当您在同一级别上有两个重叠的 NSView 时,未定义绘制顺序。您可以使用
SubviewsUsingFunction:context:
对子视图的绘制进行排序。您必须提供一个比较函数,根据某个值(例如标签)进行比较: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):结果我不得不重新排列 Interface Builder 中的一些视图,
然后在代码中:
Turns out that I had to re-arrange some of the views in Interface Builder,
then in code: