Cocoa应用程序在所有运行Mac的应用程序之上创建透明视图 [英] Cocoa app Create transparent view on top of all mac running applications

查看:304
本文介绍了Cocoa应用程序在所有运行Mac的应用程序之上创建透明视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xcode的mac osx应用程序。我想在所有应用程序之上添加一个透明的全屏视图/窗口。所以我可以在透明视图上绘制,在它后面将是任何应用程序,safari,字...等。

I am working on a mac osx application using Xcode. I would like to add a transparent full-screen view/window on top of all applications. So that I could 'draw' on the transparent view, and behind it will be whatever application, safari, word...etc.

我试过像下面这样

 NSRect rect = [[NSScreen mainScreen] frame];   //this is full screen size, but still with the status bar like time, battery, etc.

 NSWindow *overlayWindow = [[NSWindow alloc]initWithContentRect:rect
 styleMask:NSBorderlessWindowMask
 backing:NSBackingStoreBuffered
 defer:NO];
 overlayWindow.backgroundColor = [NSColor redColor];
 [self.window addChildWindow:overlayWindow ordered:NSWindowAbove];

这是我的mac应用程序的一个新的全屏子窗口。但它不是所有的应用程序,我在我的mac上运行。

It's a new full-screen child window of my mac-application. But it's not on top of all applications i am running on my mac.

所以我的问题,
如何添加视图在我的Mac屏幕视图(不仅是我的应用程序的顶视图)。
非常感谢!

So my question, How to add the view on top of my mac screen view(not only the top view of my application). Thanks so much!!!

推荐答案

请参阅Apple的 FunkyOverlayWindow示例代码。除了设置窗口的级别,您将需要设置其背景颜色以清除并将其设置为非不透明。如果它是透明的,但你仍然希望它接收鼠标事件绘制(而不是让它们传递到它后面的窗口),你需要做 [window setIgnoresMouseEvents:NO]

See Apple's FunkyOverlayWindow sample code. In addition to setting the window's level, you will need to set its background color to clear and set it to non-opaque. If it's transparent but you still want it to receive mouse events for drawing (rather than letting them pass through to the windows behind it), you'll need to do [window setIgnoresMouseEvents:NO].

这篇关于Cocoa应用程序在所有运行Mac的应用程序之上创建透明视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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