Comment avez-vous explicitement animer un CALayer de backgroundColor?

Je suis en train de construire un CABasicAnimation pour animer la propriété backgroundColor d'un Core Animation CALayer, mais je ne peux pas comprendre comment bien emballer un CGColorRef valeur à transmettre à l'animation. Par exemple:

CGColorSpaceRef rgbColorspace = CGColorSpaceCreateDeviceRGB();
CGFloat values[4] = {1.0, 0.0, 0.0, 1.0}; 
CGColorRef red = CGColorCreate(rgbColorspace, values); 
CGColorSpaceRelease(rgbColorspace);

CABasicAnimation *selectionAnimation = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
[selectionAnimation setDuration:0.5f];
[selectionAnimation setToValue:[NSValue valueWithPointer:red]];
[layer addAnimation:selectionAnimation forKey:@"selectionAnimation"];

semble ne rien faire à la propriété backgroundColor, je suppose parce que de remettre un pointeur enveloppé dans un NSValue n'est pas la façon de le transmettre.

backgroundColor est un animables propriété de CALayer, donc ma question est: comment définissez-vous le Partir de ou Vers des valeurs pour cette propriété particulière (de préférence dans un Mac /iPhone indépendant de la plate-way)?

InformationsquelleAutor Brad Larson | 2009-02-05