第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

如何為UILabel的背景色設(shè)置動畫?

如何為UILabel的背景色設(shè)置動畫?

iOS
有只小跳蛙 2019-10-29 15:04:52
看起來應(yīng)該可以,但不能。顏色立即變?yōu)榫G色。self.labelCorrection.backgroundColor = [UIColor whiteColor];[UIView animateWithDuration:2.0 animations:^{    self.labelCorrection.backgroundColor = [UIColor greenColor];}];
查看完整描述

3 回答

?
慕姐8265434

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


查看完整回答
反對 回復(fù) 2019-10-29
?
智慧大石

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

}


查看完整回答
反對 回復(fù) 2019-10-29
  • 3 回答
  • 0 關(guān)注
  • 576 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號