开发者

CAKeyframeAnimation for backgroundColor...causes crash

开发者 https://www.devze.com 2023-03-09 02:07 出处:网络
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?

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)],

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号