在IKImageBrowserCell中动画CALayer [英] Animating CALayer in IKImageBrowserCell

查看:221
本文介绍了在IKImageBrowserCell中动画CALayer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义图像浏览器视图与IKImageBrowserCell子类,我添加了一个小标志图形,我想在一些场合动画。



像在Panic的Coda网站视图(我猜猜是一个ImageBrowserView自定义..的i标志..对吗?)。在Coda的网站上,如果你将鼠标悬停在一个项目上,那么我会消失,当你悬停在外面时,它会消失。



尝试重现这种效果, 。



我已经将IKImageBrowserCell子类化,并且在layerForType期间保存对符号图层的引用。





悬停检测代码本身工作,我知道从NSLogs,但隐式动画



有任何建议吗?





感谢

解决方案

尝试:

  CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@opacity]; 
animation.duration = 0.8s //淡出的持续时间
animation.repeatCount = 0;
animation.autoreverses = NO;
animation.fromValue = [NSNumber numberWithFloat:1.0];
animation.toValue = [NSNumber numberWithFloat:0.0];
[myLayer addAnimation:animation forKey @fadeOut];

要使图层淡入,请使用twoValue切换fromValue并重命名该键。



希望这有助于。


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

解决方案

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.

这篇关于在IKImageBrowserCell中动画CALayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆