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:[UI开发者_StackOverflowColor 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?
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.
精彩评论