【问题标题】:How to draw an fullscreen overlay and text+text field over it?如何在其上绘制全屏覆盖和文本+文本字段?
【发布时间】:2012-11-12 04:42:03
【问题描述】:

有没有办法绘制全屏覆盖,然后在上面绘制一个标签+文本字段?

我已经做了什么:

当用户点击按钮时,屏幕应该被覆盖。

在我写的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];

它工作得很好,但没有任何动画并且我真的不知道如何在它上面绘制对象(标签/文本字段)?

或者,我应该将此方法移到另一个类中吗?

【问题讨论】:

    标签: objective-c xcode cocoa


    【解决方案1】:

    至于动画,有很多方法..我做

    mainWindow.alphaValue = 0;
    [mainWindow orderFrontRegardless];
    [[mainWindow animator] setAlphaValue:1.0];
    

    至于标签,只需添加一个带有 HUGE NSFont 的 NSTextField 作为子视图

    NSTextField *label = ... 
    [[mainWindow contentView] addSubview:label];
    

    附言就像使用标签一样,您可以添加任何其他视图:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-12
      • 2013-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多