CAKeyframeAnimation for backgroundColor...causes crash
I enumerate an array with this code and it cra开发者_Python百科shes. I think it is because I am wrapping the colors incorrectly, but how should I pass them?
CAKeyframeAnimation *iAnimation = [CAKeyframeAnimation animationWithKeyPath:@"backgroundColor"];
NSArray *iTimes;
NSArray *iValues;
NSInteger iTag = iButton.tag;
iTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:(iTimeBlock * iTag)],
[NSNumber numberWithFloat:(iTimeBlock * iTag + 1)],
[NSNumber numberWithFloat:iTimeBlock * (iTag + 2)], nil];
iValues = [NSArray arrayWithObjects:
iButton.backgroundColor,
iButton.color, // my subclass has this property
iButton.backgroundColor, nil];
[iAnimation setKeyTimes:iTimes];
[iAnimation setValues:iValues];
[iAnimation setDuration:21.0];
[iButton.layer addAnimation:iAnimation
forKey:@"FlashColor"];
iValues = [NSArray arrayWithObjects:
(id)iButton.backgroundColor.CGColor,
(id)iButton.color.CGColor,
(id)iButton.backgroundColor.CGColor,
nil];
To get the color of a UIButton you can do like this :
[iButton backgroundColor];
you probably don't need this stuff :
[NSValue valueWithBytes:iButton.backgroundColor objCType:@encode(UIColor)],
精彩评论