2013-12-18 59 views
1

我希望能夠檢測到雙擊並且手指觸摸該圖層時。這不完全是單擊,因爲對於發生敲擊,手指必須觸摸並離開屏幕。我想要檢測一個或多個手指觸摸視圖的確切時刻。UIGestureRecognizer對於單擊的奇怪行爲

這是我的代碼:

doubleTap = [[UITapGestureRecognizer alloc] 
        initWithTarget:self 
        action:@selector(handleDoubleTap:)]; 
    [doubleTap setCancelsTouchesInView:NO]; 
    [doubleTap setNumberOfTapsRequired:2]; 
    [doubleTap setDelegate:self]; 
    [self.view addGestureRecognizer:doubleTap]; 


    singleTap = [[UITapGestureRecognizer alloc] 
       initWithTarget:self 
       action:@selector(handleSingleTap:)]; 
    [singleTap setCancelsTouchesInView:NO]; 
    [singleTap setNumberOfTapsRequired:1]; 
    [singleTap setNumberOfTouchesRequired:1]; 
    [singleTap requireGestureRecognizerToFail: doubleTap]; 
    [singleTap setDelegate:self]; 
    [self.view addGestureRecognizer:singleTap]; 

這是我如何處理單輕叩

- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer { 

    if(recognizer.state == UIGestureRecognizerStateBegan) { 
     [self doSomething]; 
    } 
} 

這個代碼只是觸發handleSingleTap方法,當手指離開,所以狀態總是有UIGestureRecognizerStateEnd。

我該如何觸發一個或多個手指觸摸視圖,但手指仍然在那裏?

謝謝。

+2

如果你的視圖是'UIView',你可以簡單地使用'touchesBegan:'和'touchesMoved:'來檢測手指何時還在那裏 – tipycalFlow

+0

使用長按手勢識別器minimumPressDuration = 0.001 – Mavericks

+0

@Mavericks - 我想你這裏可能有一點意義。我會檢查出來的。\ – SpaceDog

回答

1

在minimumPressDuration = 0.001時使用長按手勢識別器。

+0

P E R F E C T! – SpaceDog