【发布时间】:2011-06-22 15:49:26
【问题描述】:
我有一个gridView,我用来显示几个GridViewCell : UIView。 GidViewCell 给自己添加了一个 UILabel 并附加了一个UITapGestureRecognizer 给自己。
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[self addGestureRecognizer:gestureRecognizer];
[gestureRecognizer release];
在tapped:我想播放一些动画,包括改变标签的背景颜色
- (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];
}
但标签只是在眨眼之间闪烁蓝色——如果有的话。 如果我使用相同的代码但调整标签的 alpha 而不是背景颜色,一切都会按预期工作。
Apple's docs 将 backgroundColor 列为动画。 是吗?我做错了吗?
【问题讨论】:
-
@bioffe 因为这不是 iPhone 特有的问题,我想说,[ios] 会是更好的标签
-
是的,[ios] 是更好的标签。谢谢你。顺便说一句,我的 UILabel 的背景不会使用此解决方案进行动画处理。将 CATextLayer 添加到 UILabel.layer 时,我的运气要好得多。
-
试试这个,不需要做所有这些:stackoverflow.com/a/20892927/189924
-
@strange,你不需要在一个 3 岁的问题上提高噪音水平并接受答案。
-
@vikingosegundo SDK 在 3 年内发生了变化,这是一个很受欢迎的问题。我在寻找解决方案时登陆页面并找到了一个非常想分享的解决方案。我推荐的方法更干净,更容易,不需要上述技巧(不尊重您的回答)。如果冒犯了您,我们深表歉意。
标签: objective-c ios cocoa-touch uianimation