在 IKImageBrowserCell 中对 CALayer 进行动画处理

发布于 2024-09-27 08:20:49 字数 484 浏览 1 评论 0原文

我有一个带有 IKImageBrowserCell 子类的自定义图像浏览器视图,其中我添加了一些我想在某些情况下设置动画的符号图形。

它有点像 Panic 的 Coda Sites 视图上的“i”符号(我猜这是自定义的 ImageBrowserView ......对吗?)。在 Coda 的站点视图中,如果您将鼠标悬停在某个项目上,小 i 就会淡入,当您将鼠标悬停在项目上时,小 i 就会消失。

试图重现这种效果,但我很挣扎。

我已经对 IKImageBrowserCell 进行了子类化,并且在 layerForType 期间保存了对标志图层的引用。

然后,当鼠标移过时,我尝试更改不透明度,但它没有改变。

我从 NSLogs 知道悬停检测代码本身有效,但 CALayer 的隐式动画 (signLayer.opacity = 1.0) 永远不会启动。

有什么建议吗?

也许我错过了一些东西(对核心动画来说有点新)。

谢谢

I've got a custom image browser view with IKImageBrowserCell subclass where I've added a little sign graphic that I would like to animate on some occasions.

It's kind of like the "i" sign on Panic's Coda Sites view (which I'm guessing is an ImageBrowserView customized.. right?). On Coda's sites view, if you hover on a project the little i fades in and goes away when you hover out.

Trying to reproduce that effect, and i'm struggling.

I've subclassed IKImageBrowserCell and I'm saving a reference to the sign's layer during layerForType..

Then when the mouse goes over i'm trying to change the opacity but it's not changing.

The hover detection code itself works, I know from NSLogs but the implicit animation of CALayer (signLayer.opacity = 1.0) never kicks in.

Any suggestion?

Maybe I'm missing something (kinda new to Core Animation).

Thanks

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

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

发布评论

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

评论(1

破晓 2024-10-04 08:20:49

试试这个:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.duration = 0.8s //the duration of the fade
animation.repeatCount = 0;
animation.autoreverses = NO;
animation.fromValue = [NSNumber numberWithFloat:1.0];
animation.toValue = [NSNumber numberWithFloat:0.0];
[myLayer addAnimation:animation forKey@"fadeOut"];

要淡入图层,请将 fromValue 与 TwoValue 切换并重命名该键。

希望这有帮助。

Try this:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.duration = 0.8s //the duration of the fade
animation.repeatCount = 0;
animation.autoreverses = NO;
animation.fromValue = [NSNumber numberWithFloat:1.0];
animation.toValue = [NSNumber numberWithFloat:0.0];
[myLayer addAnimation:animation forKey@"fadeOut"];

To fade the layer in, switch the fromValue with the twoValue and rename the key.

Hope this helps.

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