【问题标题】:Change Alpha on Main Window - Cocoa在主窗口更改 Alpha - Cocoa
【发布时间】:2009-09-19 16:48:43
【问题描述】:

我想知道当我打开应用程序和关闭应用程序时是否可以慢慢增加 alpha MainWindow。我知道它可能涉及计时器之类的事情,但我以前从未处理过这种事情。我需要你们的帮助......!

凯文

【问题讨论】:

    标签: objective-c cocoa xcode time alpha


    【解决方案1】:

    使用 NSViewAnimation。尽管有这个名字,但它适用于窗口和视图。

    【讨论】:

      【解决方案2】:

      [self setAlphaValue:0];

      这将设置窗口的 alpha。只需创建一个 NSTimer 来增加或减少 alpha 值。该值是一个 。

      【讨论】:

      • 我得到这个错误,当我使用 setAlphaValue... 你能告诉我一步一步怎么做吗?
      • 我使用的代码是:- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag { if ((self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])) { //[self setAlphaValue:0]; // 关闭不透明度,使窗口中没有被绘制的部分是透明的。 [自我设置不透明:否]; //在此处放置您需要的任何进一步初始化 } return self; }
      • 是的,它是......这有点令人困惑......我是否将所有内容放在一行中?以及我将如何在 NSTimer 中解释这一点。我希望我的应用程序从 0 alpha 到 100 缓慢
      • 它是多行,只是格式不正确。要添加 NSTimer,您所要做的就是初始化它(在 .h 中)然后在 .m 中将这一行添加到 awakefromnib: timer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(onTimer) userInfo :nil 重复:YES]; timer=timername onTimer=要调用的东西,1.0=1 秒。然后在调用时只需将其添加到 int 然后在 setAlphaValue 上将其设置为 int(还包括检查它是否超过 100,您不希望它浪费内存)
      • 您不想将 alpha 设置为 100,因为它是一个乘数,而不是一个百分比。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多