Is UILabel's backgroundColor not animatable?

让人想犯罪 __ 提交于 2019-11-28 01:52:41

问题


I have a gridView, I use to display several GridViewCell : UIView. The GidViewCell adds an UILabel to itself and attaches anUITapGestureRecognizer to itself.

UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[self addGestureRecognizer:gestureRecognizer];
[gestureRecognizer release];

in tapped: I want to play some animation, including changing the background color of the label

- (void) tapped:(id)sender {
    [UIView animateWithDuration:1.0
                          delay:0
                        options:(UIViewAnimationOptionAllowUserInteraction)
                     animations:^{ 
                         [(UILabel *)[[self subviews] objectAtIndex:0] setBackgroundColor:[UIColor blueColor]];
                     }  
                     completion:^(BOOL finished){
                         [(UILabel *)[[self subviews] objectAtIndex:0] setBackgroundColor:[UIColor whiteColor]];
                     }
     ];     
[self.delegate didSelectGridViewCell:self];
}

But the label just flashes blue for a blink of an eye — if at all. If I use the same code but adjust the alpha of the label instead of the background color, everything works as expected.

Apple's docs lists backgroundColor as animatable. Is it? Am I doing something wrong?


回答1:


I've never tried this myself but I know of someone who has. I don't know if this is a bug in the documentation or in the code. I'm assuming the latter since UILabel inherits from UIView and I know for sure that you're able to animate the background of a UIView. The workaround apparently is to drill down to the underlying CALayer and set the background color there.



来源:https://stackoverflow.com/questions/6442774/is-uilabels-backgroundcolor-not-animatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!