确定是否绘制NSView的正确方法 [英] Proper way to determine if NSView is drawn
问题描述
是否有正确的方法来确定 NSView
是否实际绘制在当前视图层次结构中,考虑以下情况:
Is there a proper way to determine if a NSView
is actually drawn in the current view hierarchy or not, considering cases like:
- 视图完全在屏幕外(不是强制性的)
- 视图不在视图层次结构顶部
不幸的是, -isHidden
和 -isHiddenOrHasHiddenAncestor
不设置时一个视图消失,因为一个标签视图切换到另一个标签。
The -isHidden
and -isHiddenOrHasHiddenAncestor
are unfortunately not set when e.g. a view disappears because a tab view switches to another tab.
这是因为我有一个附加的子窗口,我想能够隐藏它
The reason for this is that I have an attached child window and I would like to be able to hide it as well when the view that it is attached to is not drawn.
推荐答案
我发现了一个技巧来判断它是否可见,但它需要子类化。它通过在2个事件上切换一个ivar来工作。
I have found a trick to tell if it is visible, but it requires subclassing. It works by toggling an ivar on 2 events.
- (void)discardCursorRects {
isDrawn_ = NO;
[super discardCursorRects];
}
- (void)resetCursorRects {
isDrawn_ = YES;
[super resetCursorRects];
}
这篇关于确定是否绘制NSView的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!