2011-09-06 133 views
1

我有一個UILongPressGestureRecognizer火災的方法-(void)didPress。當前視圖默認爲UIImagedidPress使UIImage消失在屏幕上。但是,只要用戶仍然很長時間按下,圖像就只能從屏幕上消失。一旦用戶放開最初的長按,圖像會再次出現。我的代碼已經可以處理最初的長按,但我不確定如何確定用戶何時放棄了長時間的觸摸。UIGestureRecognizer水龍頭和刪除

回答

4

您應該通過UILongPressGestureRecognizer到你的方法,並檢查姿態,狀態當用戶釋放他的手指/手指在屏幕中,它會發送UIGestureRecognizerStateEnded

- (void)didPress:(UILongPressGestureRecognizer *)recognizer { 
    if (recognizer.state == UIGestureRecognizerStateBegan) { 
    NSLog(@"Started"); 
    } 
    if (recognizer.state == UIGestureRecognizerStateEnded) { 
    NSLog(@"Finished");  
    } 
} 

的狀態下使用的touchesBegan: withEvent:早在UIGestureRecognizer的

之前