亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何為UILabel的背景色設置動畫?

如何為UILabel的背景色設置動畫?

iOS
守著星空守著你 2019-12-13 17:10:29
看起來應該可以,但不能。顏色立即變為綠色。self.labelCorrection.backgroundColor = [UIColor whiteColor];[UIView animateWithDuration:2.0 animations:^{    self.labelCorrection.backgroundColor = [UIColor greenColor];}];
查看完整描述

3 回答

?
翻翻過去那場雪

TA貢獻2065條經驗 獲得超14個贊

我在任何地方都找不到文檔,但是它的backgroundColor屬性似乎UILabel不是可動畫的,因為您的代碼可以在vanilla上正常工作UIView。但是,只要您不設置標簽視圖本身的背景顏色,此hack似乎就可以起作用:


#import <QuartzCore/QuartzCore.h>


...


theLabel.layer.backgroundColor = [UIColor whiteColor].CGColor;


[UIView animateWithDuration:2.0 animations:^{

    theLabel.layer.backgroundColor = [UIColor greenColor].CGColor;

} completion:NULL];



查看完整回答
反對 回復 2019-12-14
?
慕容708150

TA貢獻1831條經驗 獲得超4個贊

您可以為其設置動畫,但是由于某種原因,我必須首先(以編程方式)將其設置為clearColor。否則,動畫要么不起作用,要么不可見。


我正在自定義表格單元中設置UILabel的背景色。這是willDisplayCell方法中的代碼。我不會嘗試在cellForRow中設置動畫,因為很多布局都被表格修改了。


- (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"];

}



查看完整回答
反對 回復 2019-12-14
  • 3 回答
  • 0 關注
  • 551 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號