在 Mac OS X (Lion) 上创建全屏覆盖的最优雅方式? [英] The most elegant way of creating a fullscreen overlay on Mac OS X (Lion)?

查看:23
本文介绍了在 Mac OS X (Lion) 上创建全屏覆盖的最优雅方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在 Mac OS X 下创建全屏覆盖的最佳"方式.我想创建一个透明或半透明的覆盖,它关心鼠标事件并显示其他输入/输出元素.

此叠加层应位于所有其他 GUI 项目之上(如 CMD-Tab 叠加层).

你知道如何有效地做到这一点吗?目前我正在玩这种代码:

int windowLevel = CGShieldingWindowLevel();NSRect windowRect = [[NSScreen mainScreen] frame];NSWindow *overlayWindow = [[NSWindow alloc] initWithContentRect:windowRectstyleMask:NSBorderlessWindowMask支持:NSBackingStoreBuffered推迟:否屏幕:[NSScreen mainScreen]];[overlayWindow setReleasedWhenClosed:YES];[overlayWindow setLevel:windowLevel];[overlayWindow setBackgroundColor:[NSColor colorWithCalibratedRed:0.0绿色:0.0蓝色:0.0阿尔法:0.5]];[overlayWindow setAlphaValue:1.0];[overlayWindow setOpaque:NO];[overlayWindow setIgnoresMouseEvents:NO];[overlayWindow makeKeyAndOrderFront:nil];

...它工作正常,但我没有选择启动任何类型的动画,例如缓慢增加透明度(缓慢调暗屏幕)等.

虽然我不明白如何把这个窗口放在后台,不释放它,让它不时弹出.

那么有没有更好或标准"的方法来做到这一点?

解决方案

您可以使用 NSViewAnimation.是的,它也适用于 Windows.

动画的目标应该是窗口,其效果应该是淡入或淡出,具体取决于您是显示还是隐藏它.省略框架键,因为您可能不想移动或调整窗口大小.

当然,您应该省略 makeKeyAndOrderFront: 消息,因为您将使用淡入效果对其进行排序.

I'm searching for the "best" way of creating a fullscreen overlay under Mac OS X. I want to create a transparent or semi-transparent overlay, which cares about mouse events and shows other input/output elements.

This overlay should be above every other GUI items (like the CMD-Tab overlay).

Do you know how to do it effectively? At the moment I'm playing around with this kind of code:

int windowLevel = CGShieldingWindowLevel();
NSRect windowRect = [[NSScreen mainScreen] frame];
NSWindow *overlayWindow = [[NSWindow alloc] initWithContentRect:windowRect
                                          styleMask:NSBorderlessWindowMask
                                            backing:NSBackingStoreBuffered
                                              defer:NO
                                             screen:[NSScreen mainScreen]];

[overlayWindow setReleasedWhenClosed:YES];
[overlayWindow setLevel:windowLevel];
[overlayWindow setBackgroundColor:[NSColor colorWithCalibratedRed:0.0
                                                          green:0.0
                                                           blue:0.0
                                                          alpha:0.5]];
[overlayWindow setAlphaValue:1.0];
[overlayWindow setOpaque:NO];
[overlayWindow setIgnoresMouseEvents:NO];
[overlayWindow makeKeyAndOrderFront:nil];

…and it works fine but I've got no options to initiate any kind of animations like slowly increasing the transparency (slowly dimming the screen) etc.

Although I'm not understanding how to put this window in the background, without releasing it and let it pop up time to time.

So is there a better or "standard" way to do it?

解决方案

You can use NSViewAnimation. Yes, it works on windows, too.

Your animation's target should be the window, and its effect should be fade-in or fade-out, depending on whether you're showing or hiding it. Leave out the frame keys, since you probably don't want to move or resize the window.

Of course, you should leave out the makeKeyAndOrderFront: message, since you'll be ordering it front with the fade-in effect.

这篇关于在 Mac OS X (Lion) 上创建全屏覆盖的最优雅方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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