Is there a proper way to handle overlapping NSView siblings?

后端 未结 5 515
终归单人心
终归单人心 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 06:45

    In order to ensure that NSView B always overlaps NSView A, make sure that you use the correct NSWindowOrderingMode when you are adding the subview:

    [parentView addSubview:B positioned:NSWindowAbove relativeTo:A];
    

    You should also keep in mind that the hidden portions of A will not be asked to redraw if view B is 100% opaque.

    If you are moving the subviews, you also need to make sure that you call -setNeedsDisplayInRect: for for the areas of the view you are uncovering.

提交回复
热议问题