NSWindow setAlpha 不生效
我的应用程序有一个窗口,当它激活时,它的 alpha 从 0 到 1 进行动画处理,并在停用时将其 alpha 设置为 0,但我发现,如果我的应用程序仅激活很长时间,则停用时 alpha 不会设置为 0时间短(<1秒)。
因此,效果是窗口在消失之前快速闪烁到视图中,然后淡入。
这几乎就像它在停用时无法将其 alpha 设置为 0 一样,因为窗口在激活时从未完成将其动画设置为 1 的操作。
如何强制 alpha 为 0? - 在 applicationWillBecomeActive 开头将其设置为 0 不起作用......
代码如下:
- (void)applicationWillBecomeActive:(NSNotification *)aNotification {
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.10];
[[mainPanel animator] setAlphaValue:1.0f];
[NSAnimationContext endGrouping];
}
- (void)applicationWillResignActive:(NSNotification *)aNotification {
[mainPanel setAlphaValue:0.0];
[mainPanel orderOut:nil];
}
my app has a window animating it's alpha from 0 to 1 when it becomes active and setting it's alpha to 0 on deactivate, but I'm finding that the alpha isn't set to 0 on deactivate if my app is only activated for a very short time (< 1 second).
So the effect is that the window just quickly blinks into view before disappearing and then fading in.
It's almost as if it doesn't get to set it's alpha to 0 on deactivate because the window never finished animating it to 1 when it was activated.
How can I force the alpha to 0? - Setting it to 0 at the beginning of applicationWillBecomeActive doesn't work....
Here's the code:
- (void)applicationWillBecomeActive:(NSNotification *)aNotification {
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.10];
[[mainPanel animator] setAlphaValue:1.0f];
[NSAnimationContext endGrouping];
}
- (void)applicationWillResignActive:(NSNotification *)aNotification {
[mainPanel setAlphaValue:0.0];
[mainPanel orderOut:nil];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论