4

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

Ben
  • 20,737
  • 12
  • 71
  • 115
  • And via debugging/logging, you see that signLayer is not nil at the time you change the opacity? Remember that it will not crash if you try to set the opacity of the nil instance. – Aviad Ben Dov Oct 22 '10 at 09:24
  • @Aviad. First thing i checked :) there's definitely a CALayer there – Ben Oct 23 '10 at 03:44
  • And you're sure the layer is displayed otherwise (suppose it was initialized with opacity to 1?). It might be that it _needsDisplay_ or perhaps that it's so invisible it doesn't catch the hover (though you said you checked that) – Aviad Ben Dov Oct 23 '10 at 09:59
  • @Aviad. Tried that too. I'm starting on a 0.5 opacity to make sure it's there. needsDisplay doesn't seems to change anything. – Ben Oct 25 '10 at 02:19

1 Answers1

0

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
  • 54,662
  • 15
  • 117
  • 144
  • I tried that before, that doesn't work either. Basically no core animation kicks in. – Ben Oct 22 '10 at 00:24
  • Did you set the layer's delegate to it's view controller? – Evan Mulawski Oct 22 '10 at 00:32
  • 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 Oct 22 '10 at 03:18
  • 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 Oct 22 '10 at 11:47
  • 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 Oct 23 '10 at 03:44