我有一個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