Sibling NSView在可可中的z顺序 [英] Sibling NSView z-ordering in Cocoa

查看:388
本文介绍了Sibling NSView在可可中的z顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

z-ordering如何在Cocoa中使用sibling NSViews?我很困惑,因为我在Apple的文档和API中发现了冲突的信息来源。 (注意:子视图显然是在其父视图之上显示的,我在这里明确谈到兄弟视图。)

How does z-ordering work with sibling NSViews in Cocoa? I'm confused because I'm finding conflicting sources of information in Apple's docs and APIs. (Note: Subviews are obviously rendered on top of its parent view, I am talking explicitly about sibling views here).

假设A 是,您可以定义同级的z顺序 NSViews


  • IB 中,您可以将视图叠加在一起,而且它们将始终以您期望的方式进行合成。

  • Xcode中的编辑器菜单中有一些按钮,名为发送回,发送转发等。

  • NSView 也有一个名为 - (void)addSubview:(NSView *)aView的方法:(NSWindowOrderingMode)place relativeTo:(NSView *)otherView; 这似乎暗示着有一个明确的排序。

  • In IB you can place views on top of each other and they will always be composited in the way you'd expect.
  • There's buttons in Xcode under the Editor menu named "Send to Back", "Send Forward" etc.
  • The NSView also has a method named - (void)addSubview:(NSView *)aView positioned:(NSWindowOrderingMode)place relativeTo:(NSView *)otherView; which seems to imply that there is a well defined ordering.

假设B :没有办法,兄弟的z顺序 NSViews 在运行时是未定义的,有时它工作,有时它不工作,不信任它!

Hypothesis B: "No way, z-order of sibling NSViews is undefined at runtime. Sometimes it works, sometimes it doesn't. Don't trust it!"


  • Apple的文档(查看编程指南)state:出于性能原因,Cocoa不会强制在同级视图中进行剪裁,或者在同级视图重叠时保证正确的无效和绘制行为。如果您想在另一个视图前绘制视图,则应该将前视图设置为后视图的子视图(或后代)。

  • Apple's Docs (View Programming guide) state: 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.

那么这是什么呢?

推荐答案

是的,NSView兄弟 允许重叠,Apple文档已过期:

Yes, NSView siblings are allowed to overlap, the Apple docs are out of date: Are layer-backed NSView siblings allowed to overlap?

此外,z顺序取决于子视图在父视图的<$ c $中的顺序c> subviews 数组。

Also, the z-order depends on the order of the subviews in the parent view's subviews array.

这篇关于Sibling NSView在可可中的z顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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