有没有正确的方法来处理重叠的NSView兄弟姐妹? [英] Is there a proper way to handle overlapping NSView siblings?

查看:112
本文介绍了有没有正确的方法来处理重叠的NSView兄弟姐妹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个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:


出于性能原因,Cocoa不会强制在兄弟视图之间进行剪切或保证正确的无效和绘图行为视图重叠。如果您想在另一个视图前绘制视图,则应该将前视图设为后视图的子视图(或后代)。

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.

我看到一些黑客可以使它有时工作,但它不是什么你可以依靠。您需要将视图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兄弟姐妹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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