NSView或NSWindow中的孔 [英] Holes in NSView or NSWindow

查看:207
本文介绍了NSView或NSWindow中的孔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能切出NSWindow或NSView的部分,让他们看透吗?我有一个NSWindow与NSView,我想要:

IS it possible to cut out parts of a NSWindow or an NSView and make them see through? I have an NSWindow with an NSView and I want to either:

A)在NSWindow打洞,以便能看到它或

A) make a hole in the NSWindow to be able to see through it or

B)设置我的NSWindow背景有一个清晰的颜色,然后在顶部做一个NSView,并设置我的NSViews不透明度的一部分,以便能够看到桌面。

B) set my NSWindow background to have a clear color and then make an NSView on top and set a certain part of my NSViews opacity to be able to see through to the desktop.

这是我想要创建的效果:

This is the effect I am trying to create:

推荐答案

是的,这是可能的,实际上不是

Yes, it's possible, and actually not that hard.

首先,创建 NSView 的子类。在 drawRect:中,键入:

First, create a subclass of NSView. In drawRect:, type:

NSRectFillUsingOperation(NSMakeRect(100, 100, 100, 100), NSCompositeClear);

这会清除矩形中(100,100,100,100)的所有像素

接下来,将您刚刚创建的类设置为窗口内容视图的类:

Next, set the class you just made as the class of your window's content view:

确保您的 NSWindow setOpaque:NO

[window setOpaque:NO];

完成了。启动应用程式并查看结果:

And you're done. Fire up your application and see the result:

使用绘图代码来获得所需的形状,但请记住使用 NSCompositeClear 。有关合成模式的详情,请访问开发人员文件

Mess with the drawing code to get the shape you want, but remember to use NSCompositeClear. For more on compositing modes check out the developer documentation.

这篇关于NSView或NSWindow中的孔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆