The right way to determine if an NSView will be

Is there a correct way to determine if the NSView is NSView displayed in the current view hierarchy or not, given cases such as:

  • Off-screen view (optional)
  • View is not above view hierarchy

-isHidden and -isHiddenOrHasHiddenAncestor , unfortunately, are not set when, for example, the view disappears because the tab view switches to another tab.

The reason for this is that I have a child child window, and I would also like to hide it when the view it is attached to is not drawn.

+4
source share
2 answers

I found a trick to find out if this is visible, but requires a subclass. It works by switching ivar to 2 events.

 - (void)discardCursorRects { isDrawn_ = NO; [super discardCursorRects]; } - (void)resetCursorRects { isDrawn_ = YES; [super resetCursorRects]; } 
+3
source

Whether this is supposed to be (or when) drawn is β€œnothing of your business” and really has nothing to do with whether it will be on screen. Use NSView -viewDidMoveToSuperview or -viewDidMoveToWindow to control this.

0
source

Source: https://habr.com/ru/post/1344942/


All Articles