cocoashow-hidensimageviewtopmost

Cocoa: How to properly hide other views below NSImageView?


I have a view with several subviews (NSButton, NSTextField, NSPopUpButton) and a NSImageView with a spinner icon which should be displayed on top of the other views while data is retrieved from the web.

To display the NSImageView on top I have set

imageViewSpinner.wantsLayer = true
imageViewSpinner.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor

The problem is, that the focus borders and PopUpButtons are still accessible/shining through the NSImageView (see attached video).

To solve this, I could iterate over all the other subviews and set them to "isHidden" or "disabled" but I wonder, if there is a cleaner solution to this problem, for example defining the NSImageView as topmost layer without things getting through?

video


Solution

  • You could put all of the other views inside of one container view and hide that.

    You can also use a tab-less tab view to programmatically switch between view sub-hierarchies. (That basically achieves the same thing. It's better when there are more than 2 views to manage.)