[英]How to determine “TapEnded” in iOS
我想更改UIView點擊的背景顏色,我知道如何在iOS的UIView上捕獲觸摸事件和手勢。
我可以在touchesBegan
觸發時更改顏色,然后在touchesEnded
或touchesCancelled
觸發時將其更改為原始顏色。
這可以正常工作,直到用戶真正快速地單擊UIView為止,這可以由UITapGestureRecognizer
確定並更改背景顏色,但是UITapGestureRecognizer
我不知道如何更改顏色!
我不想使用某種“計時器”或類似的方法。 有什么建議嗎?
您可以通過檢查水龍頭的狀態來檢測它是否結束:
目標C
if (recognizer.state == UIGestureRecognizerStateEnded) {
// change the color here
}
迅速
if recognizer.state == .Ended {
// change the color here
}
從您的問題來看,您似乎已經通過以下UIView代表成功完成了此任務。
第二個選項是使用您已經提到的UITapGestureRecognizer。 請嘗試在手勢識別器方法中使用以下代碼。
向您的視圖添加手勢:
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTap:)];
[yourView addGestureRecognizer:tapGesture ];
您的手勢識別器方法
-(void) viewTap:(UITapGestureRecognizer *) gestureRecognizer
{
if(gestureRecognizer.state == UIGestureRecognizerStateEnded)
{
//All fingers are lifted.
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.