macoscocoansviewsetneedsdisplaysetneedsdisplayinrect

SetNeedsDisplay on NSView triggers the redrawing of the whole views hierarchy


I'm working on an app made by a NSWindow which own a lot of custom subviews, that could be opaque or not. Whenever I call SetNeedsDisplay: or SetNeedsDisplayInRect: on a subview, the system calls the drawRect of each single subview starting from the content view of the parent NSWindows.

How can it be avoided? How can I redraw just the dirty subview (it should be the default behaviour)? Is there something that I'm missing maybe in subclassing the NSView? Or in setting the properties or the syle of the parent NSWindow?

Thanks


Solution

  • Ok, I think I’ve figured it out. It seems that turning all the subviews into layer-backed views did the trick. And this is reasonable giving the way the layers are managed by the gpu and how the layer compositing is performed. But I still don't understand why, using the "classic" NSViews, no matter if they are opaque or not, siblings or children, overlapped or not , I cannot invalidate a single view without the system calls the re-drawing of the entire view hierarchy of the window