NSView改变属性动画类型

发布于 2024-12-02 11:31:13 字数 164 浏览 0 评论 0原文

我有一个 NSButton ,当我调用 [button setHidden: NO]; 时,我想为它设置动画。但是,我不想要默认的淡入淡出动画,我会就像从左滑动的动画一样。

我确信它没有那么复杂,但我正在努力在文档中找到正确的位置。有什么建议吗?

I have an NSButton that I'd like to animate when I call [button setHidden: NO]; However, I don't want the default fade animation, I'd like a slide-from-left animation instead.

I'm sure it's not that complicated, but I'm struggling to find the right location in the docs. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

骑趴 2024-12-09 11:31:13

您应该通过动画师代理来更改框架。

NSRect aFrameMoreToTheLeft = …;
[[button animator] setFrame:aFrameMoreToTheLeft];

You should change the frame via the animator proxy.

NSRect aFrameMoreToTheLeft = …;
[[button animator] setFrame:aFrameMoreToTheLeft];
因为看清所以看轻 2024-12-09 11:31:13

看起来正确的答案是向图层添加自定义动画,然后只需设置属性,而不是使用属性的默认动画器:

CATransition *animation = [CATransition animation];
[animation setDuration: 0.2];
[animation setType: kCATransitionMoveIn];
[animation setSubtype: kCATransitionFromRight];
[animation setTimingFunction: [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut]];   

[[button layer] addAnimation: animation forKey: @"slidebutton"];
[button setHidden: NO];

仍然不是 100% 清楚 Mac OS X 上 kCATransitionFade< 之间的区别/code> 和 kCATransitionReveal

Looks like the correct answer to add a custom animation to the layer, and then just set the property, instead of using the default animator for the property:

CATransition *animation = [CATransition animation];
[animation setDuration: 0.2];
[animation setType: kCATransitionMoveIn];
[animation setSubtype: kCATransitionFromRight];
[animation setTimingFunction: [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut]];   

[[button layer] addAnimation: animation forKey: @"slidebutton"];
[button setHidden: NO];

Still not 100% clear what the difference is on Mac OS X between kCATransitionFade and kCATransitionReveal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文