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 customize开发者_C百科d.. 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.
精彩评论