在 Mac OS X (Lion) 上创建全屏覆盖的最优雅方式?
我正在寻找在 Mac OS X 下创建全屏覆盖的“最佳”方法。我想创建一个透明或半透明的覆盖,它关心鼠标事件并显示其他输入/输出元素。
该覆盖层应位于所有其他 GUI 项目之上(例如 CMD-Tab 覆盖层)。
你知道如何有效地做到这一点吗?目前我正在玩这种代码:
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];
……它工作得很好,但我没有选择启动任何类型的动画,例如慢慢增加透明度(慢慢调暗屏幕)等。
虽然我不是了解如何将此窗口放在后台,而不释放它并让它不时弹出。
那么有没有更好的或“标准”的方法来做到这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 NSViewAnimation。是的,它也适用于 Windows。
动画的目标应该是窗口,其效果应该是淡入或淡出,具体取决于您是显示还是隐藏它。忽略框架关键点,因为您可能不想移动窗口或调整窗口大小。
当然,您应该省略
makeKeyAndOrderFront:
消息,因为您将在淡入效果中将其排序在前面。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.