views:

84

answers:

1

Hi,

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

A: 

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.

Evan Mulawski
I tried that before, that doesn't work either. Basically no core animation kicks in.
Ben
Did you set the layer's delegate to it's view controller?
Evan Mulawski
I'm in an IKImageBrowserCell, this isn't exactly a view controller. Why would I want to set a delegate? i'm not custom drawing the layer.
Ben
In your case, you would set the delegate to the layer's parent view. Even if you are not custom drawing the layer, the delegate is sometimes required in order to respond to drawing or animation methods.
Evan Mulawski
@Evan. I tried that but all it does is causing an infinite series of calls to layerForType.. i'm guessing the view's invalidating itself or something..
Ben