简体   繁体   中英

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?

视频

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM