Is there a proper way to handle overlapping NSView siblings?

后端 未结 5 492
终归单人心
终归单人心 2020-11-27 06:35

I\'m working on a Cocoa application, and I\'ve run into a situation where I would like to have two NSView objects overlap. I have a parent NSView which contains two subviews

5条回答
  •  爱一瞬间的悲伤
    2020-11-27 07:03

    As Nate wrote, one can use:

    self.addSubview(btn2, positioned: NSWindowOrderingMode.Above, relativeTo: btn1)
    

    However, the ordering of views is not respected as soon as you ask either of the views to redraw it self through the "needDisplay = true" call

    Siblings wont get the drawRect call, only the views direct hierarchy will.

    Update 1

    To solve this problem I had to dig deep, very deep. Probably a week of research and ive spread my findings over a few articles. The final break-through is in this article: http://eon.codes/blog/2015/12/24/The-odd-case-of-luck/

    Update 2

    Be warned though the concept is hard to understand, but it works, and it works great. Here is the end result and code to support it, links to the github repo etc: http://eon.codes/blog/2015/12/30/Graphic-framework-for-OSX/

提交回复
热议问题