3 回答

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個贊
我在任何地方都找不到文檔,但是它的backgroundColor屬性似乎UILabel不是可動畫的,因?yàn)槟拇a可以在vanilla上正常工作UIView。但是,只要您不設(shè)置標(biāo)簽視圖本身的背景顏色,此hack似乎就可以起作用:
#import <QuartzCore/QuartzCore.h>
...
theLabel.layer.backgroundColor = [UIColor whiteColor].CGColor;
[UIView animateWithDuration:2.0 animations:^{
theLabel.layer.backgroundColor = [UIColor greenColor].CGColor;
} completion:NULL];

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個贊
您可以為其設(shè)置動畫,但是由于某種原因,我必須首先(以編程方式)將其設(shè)置為clearColor。否則,動畫要么不起作用,要么不可見。
我正在自定義表格單元中設(shè)置UILabel的背景色。這是willDisplayCell方法中的代碼。我不會嘗試在cellForRow中設(shè)置動畫,因?yàn)楹芏嗖季侄急槐砀裥薷牧恕?/p>
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
((RouteListCell *)cell).name.backgroundColor = [UIColor clearColor];
[((RouteListCell *)cell).name backgroundGlowAnimationFromColor:[UIColor whiteColor] toColor:[UIColor redColor] clearAnimationsFirst:YES];
}
這是我的動畫例程:
-(void) backgroundGlowAnimationFromColor:(UIColor *)startColor toColor:(UIColor *)destColor clearAnimationsFirst:(BOOL)reset;
{
if (reset)
{
[self.layer removeAllAnimations];
}
CABasicAnimation *anAnimation = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
anAnimation.duration = 1.00;
anAnimation.repeatCount = HUGE_VAL;
anAnimation.autoreverses = YES;
anAnimation.fromValue = (id) startColor.CGColor; // [NSNumber numberWithFloat:1.0];
anAnimation.toValue = (id) destColor.CGColor; //[NSNumber numberWithFloat:0.10];
[self.layer addAnimation:anAnimation forKey:@"backgroundColor"];
}
- 3 回答
- 0 關(guān)注
- 576 瀏覽
添加回答
舉報