简体   繁体   English

在Mac OS X(Lion)上创建全屏覆盖的最优雅方法是?

[英]The most elegant way of creating a fullscreen overlay on Mac OS X (Lion)?

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. 我正在寻找在Mac OS X下创建全屏覆盖的“最佳”方法。我想创建一个透明或半透明的覆盖,它关心鼠标事件并显示其他输入/输出元素。

This overlay should be above every other GUI items (like the CMD-Tab overlay). 此覆盖图应位于所有其他GUI项之上(例如CMD-Tab覆盖图)。

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 . 您可以使用NSViewAnimation Yes, it works on windows, too. 是的,它也可以在Windows上使用。

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. 当然,您应该makeKeyAndOrderFront:消息,因为您将使用淡入效果对它进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM