我有一个UIView与一些子视图和一个点击手势识别相关联,我想模仿它有'触摸'的影响。也就是说,当轻敲发生时,我想显示容器视图具有不同的背景颜色,并且任何子视图UILabels的文本也显示为突出显示。突出显示UIView类似于UIButton
当我收到来自UITapGestureRecognizer水龙头事件,我可以改变背景颜色就好了,甚至设置的UILabel到[label setHighlighted:YES];
由于种种原因,我不能UIView的改变UIControl。
但是,如果我添加一些UIViewAnimation来恢复突出显示,没有任何反应。有什么建议么?
- (void)handleTapGesture:(UITapGestureRecognizer *)tapGesture {
[label setHighlighted:YES]; // change the label highlight property
[UIView animateWithDuration:0.20
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
[containerView setBackgroundColor:originalBgColor];
[label setHighlighted:NO]; // Problem: don't see the highlight reverted
} completion:^(BOOL finished) {
// nothing to handle here
}];
}
为什么不让它'UIButton'? – 2012-01-05 17:40:12
因为它不是我拥有的代码库,还有其他的依赖关系,所以我必须将它作为UIView。 – 2012-01-05 17:41:04
看看这个库:https://github.com/mta452/UIView-TouchHighlighting – 2016-07-23 16:21:25