4

Is there a proper way to determine if a NSView is actually drawn in the current view hierarchy or not, considering cases like:

  • The view is completely offscreen (not mandatory)
  • The view is not on top of the view hierarchy

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 Answers2

3

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];
}
0

Whether (or when) it's drawn is supposed to be "none of your business" and really have nothing to do with whether or not it's on-screen. Use NSView's -viewDidMoveToSuperview or -viewDidMoveToWindow to manage this.

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • Of course it has something todo if it's drawn (on screen) or not. `-viewDidMoveToSuperview` renders itself useless when the view is e.g. in another Tab that is not active - and therefore not visible. –  Mar 23 '11 at 17:17