有没有办法绘制全屏覆盖,然后在其上绘制标签+文本字段?
我已经做了什么:
当用户单击按钮时,屏幕应被覆盖层覆盖。
在我编写的AppDelegate.m按钮操作方法中:
NSRect frame = [[NSScreen mainScreen] frame];
self.mainWindow = [[NSWindow alloc] initWithContentRect:frame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
[self.mainWindow setAcceptsMouseMovedEvents:YES];
[self.mainWindow setOpaque:NO];
[self.mainWindow setLevel:CGShieldingWindowLevel()];
[self.mainWindow setBackgroundColor:[NSColor colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:0.7]];
[self.mainWindow orderFrontRegardless];
NSApplicationPresentationOptions options = NSApplicationPresentationDisableProcessSwitching + NSApplicationPresentationHideDock + NSApplicationPresentationDisableForceQuit + NSApplicationPresentationDisableSessionTermination + NSApplicationPresentationDisableHideApplication;
[NSApp setPresentationOptions:options];
它工作得很好,但没有任何动画&我真的不知道如何在它上面绘制对象(标签/文本字段)?
我应该将此方法移到另一个类中吗?
最佳答案
至于动画,有很多方法..我会这样做
mainWindow.alphaValue = 0;
[mainWindow orderFrontRegardless];
[[mainWindow animator] setAlphaValue:1.0];
至于标签,只需添加一个带有巨大 NSFont 的 NSTextField 作为 subview 即可
NSTextField *label = ...
[[mainWindow contentView] addSubview:label];
附:就像标签一样,您可以添加任何其他 View :)
关于objective-c - 如何在其上绘制全屏叠加层和文本+文本字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13335203/