OS X version of bringSubviewToFront:?

前端 未结 6 618
我在风中等你
我在风中等你 2021-02-08 19:07

I need to replicate the function of bringSubviewToFront: on the iPhone, but I am programming on the Mac. How can this be done?

6条回答
  •  闹比i
    闹比i (楼主)
    2021-02-08 19:26

    Pete Rossi's answer didn't work for me because I needed to pop the the view to front when dragging it with the mouse. However, along the same lines the following did work without killing the mouse:

    CALayer* superlayer = [[view layer] superlayer];
    [[view layer] removeFromSuperlayer];
    [superlayer addSublayer:[view layer]];
    

    Also, the following placed in a NSView subclass or category is pretty handy:

    - (void) bringToFront {
        CALayer* superlayer = [[self layer] superlayer];
        [[self layer] removeFromSuperlayer];
        [superlayer addSublayer:[self layer]];
    }
    

提交回复
热议问题