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

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

问题描述

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

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.

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

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.

当然,您应该省略makeKeyAndOrderFront:消息,因为您将使用渐入效果将其顺序订购.

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天全站免登陆