2011-10-19 26 views
0

我正在努力將手勢集成到iPad的繪圖應用程序中。例如,我想用三根手指向左滑動以撤消繪圖步驟。需要延遲觸摸3個手指滑動而不是1個手指滑動

我遇到了阻止觸摸數據轉到touchesBegan的問題:withEvent:這會導致在執行手勢時將屏幕繪製到屏幕上。

如果我使用delayTouchesBegan屬性,則可以防止三指滑動傳遞此觸摸數據。但是,當用戶試圖畫出一條向左的線時,它也會延遲繪圖。這導致該行從遠離用戶開始繪製的地方開始。

如何確保我的應用程序只延遲三指輕掃而不是單指輕掃?

UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; 

recognizer.numberOfTouchesRequired = 3; 
recognizer.direction = UISwipeGestureRecognizerDirectionLeft; 
recognizer.delaysTouchesBegan = YES; 

[self.view addGestureRecognizer:recognizer]; 

回答

2

我找到了解決這個問題的辦法。而不是使用手勢識別器的delayTouchesBegan屬性,您可以使用傳入各種觸摸方法的UIEvent檢測觸摸的數量。然後,只需在touchBegan:withEvent:,touchesMoved:withEvent:和touchesEnded:withEvent:方法中限制動作,僅在有一次觸摸時執行。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    //only process touch data if there is a single touch 
    if ([[event allTouches] count] == 1) { 
     //draw 
    } 
} 
1

這是手勢已知的問題。沒有辦法繞過它,除此之外,選擇退出UISwipeGestureRecognizer並使用touchesBegan/Ended手動執行手勢處理。然後,您可以設置一個具有較低閾值的自定義計時器。

+0

你知道如何設置類似的東西嗎? – robhasacamera

+0

http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/MultitouchEvents/MultitouchEvents.html – logancautrell

+0

找到了一個不需要設置自定義手勢識別器的解決方案。感謝您的幫助,文章提供了一些我需要了解如何處理多點觸控事件的信息。 – robhasacamera