问题描述
我正在处理一个Cocoa应用程序,我遇到了一种情况,我想有两个NSView对象重叠。我有一个父NSView包含两个子视图(NSView A和NSView B),每个都可以有自己的几个子视图。
I'm working on a Cocoa application, and I've run into a situation where I would like to have two NSView objects overlap. I have a parent NSView which contains two subviews (NSView A and NSView B), each of which can have several subviews of their own.
有一个正确的方法来处理这种重叠? NSView B将始终在高于NSView A上,因此我想要遮蔽NSView A的重叠部分。
Is there a proper way to handle this kind of overlap? NSView B would always be "above" NSView A, so I want the overlapped portions of NSView A to be masked out.
推荐答案
如果你的应用程序只有10.5,打开视图的图层,它应该工作。
If your application is 10.5-only, turn on layers for the views and it should just work.
如果您的意思是支持10.4及以下版本,您需要找到一种不让视图重叠的方法,因为重叠的同级视图是未定义的行为。正如视图编程指南所说:
If you're meaning to support 10.4 and below, you'll need to find a way not to have the views overlap, because overlapping sibling views is undefined behavior. As the View Programming Guide says:
我看到一些黑客可以使它有时工作,但它不是什么你可以依靠。您需要将视图A作为视图B的子视图,或者创建一个处理其两项职责的大视图。
I've seen some hacks that can make it kinda work sometimes, but it's not anything you can rely on. You'll need to either make View A a subview of View B or make one giant view that handles both of their duties.
这篇关于有没有正确的方法来处理重叠的NSView兄弟姐妹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!