How to make a transparent NSView subclass handle mouse events?

后端 未结 7 1717
清歌不尽
清歌不尽 2021-02-04 10:31

The problem

I have a transparent NSView on a transparent NSWindow. The view\'s drawRect: method draws some content (NSIma

7条回答
  •  没有蜡笔的小新
    2021-02-04 11:15

    You can do:

    NSView* windowContent = [window contentView];
    [windowContent setWantsLayer:YES]
    

    Making sure that the background is transparent:

    [[windowContent layer] setBackgroundColor:[[NSColor clearColor] CGColor]];
    

    Another option would be to add a transparent background image that fills the contentView.

提交回复
热议问题