z 排序如何与 Cocoa 中的兄弟 NSView 一起使用?我很困惑,因为我在 Apple 的文档和 API 中发现了相互矛盾的信息来源。(注意:子视图显然是在其父视图之上呈现的,我在这里明确谈论的是兄弟视图)。
假设 A:“是的,您可以定义兄弟的 z 顺序NSViews
”
IB
您可以将视图放在彼此之上,它们将始终以您期望的方式组合。- Xcode 中的
Editor
菜单下有名为“Send to Back”、“Send Forward”等的按钮。 NSView
也有一个名为的方法,- (void)addSubview:(NSView *)aView positioned:(NSWindowOrderingMode)place relativeTo:(NSView *)otherView;
它似乎暗示有一个明确定义的排序。
假设 B:“不可能,兄弟的 z 顺序NSViews
在运行时是未定义的。有时有效,有时无效。不要相信它!”
- Apple 的文档(查看编程指南)状态:
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.
那么是哪一个呢?