2015-05-11 11 views
0

我如何獲得多點觸控和單點觸控事件?ios未在UILongPressGestureRecognizer中獲得其他手指(多點觸控)事件

我嘗試用左手指觸摸移動(而不是觸摸),現在我在屏幕上單擊右手指,但我嘗試獲取正確的手指觸摸事件或觸摸點(此時左手指仍然在屏幕上移動)。

我設置了日誌[手勢numberOfTouches]或[手勢numberOfTouchesRequired]。我仍然得到1,得不到2.

在我viewDidLoad方法我設置下面的代碼:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
self.view.multipleTouchEnabled = YES; 
self.view.exclusiveTouch = NO; 

UILongPressGestureRecognizer *panelLongPressGestureRecognizer = 
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(panelLongPressRecgonizerAction:)]; 
panelLongPressGestureRecognizer.delegate = self; 

//panelLongPressGestureRecognizer.numberOfTapsRequired = 1; 
//panelLongPressGestureRecognizer.numberOfTouchesRequired = 1; 
panelLongPressGestureRecognizer.minimumPressDuration = 0.001; 
[self.view addGestureRecognizer:panelLongPressGestureRecognizer]; 


UILongPressGestureRecognizer *panelLongDoublePressGestureRecognizer = 
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(panelLongPressRecgonizerAction:)]; 
panelLongDoublePressGestureRecognizer.delegate = self; 
panelLongDoublePressGestureRecognizer.numberOfTapsRequired = 2; 
panelLongDoublePressGestureRecognizer.numberOfTouchesRequired = 2; 
panelLongDoublePressGestureRecognizer.minimumPressDuration = 0.001; 
[self.view addGestureRecognizer:panelLongDoublePressGestureRecognizer]; 
} 

- (void)panelLongPressRecgonizerAction:(UILongPressGestureRecognizer *) gestureRecognizer 
{ 
switch (gestureRecognizer.state) { 
    case UIGestureRecognizerStateBegan: 
     NSLog(@" === long press began ==="); 
     break; 
    case UIGestureRecognizerStatePossible: 
     break; 
    case UIGestureRecognizerStateChanged: 
     NSLog(@" === long press changed ==="); 
     [self pressChanged:gestureRecognizer]; 
     break; 
    case UIGestureRecognizerStateEnded: 
     NSLog(@" === long press end ==="); 
     break; 
    case UIGestureRecognizerStateCancelled: 
     NSLog(@" === long press cancell ==="); 
     break; 
    case UIGestureRecognizerStateFailed: 
     NSLog(@" === long press failed ==="); 
     break; 


} 
NSLog(@" "); 

}

- (void) pressChanged:(UILongPressGestureRecognizer *) gesture 
{ 
    NSLog(@"moved guesture.number of touches:%ld", [gesture numberOfTouches]); 
    NSLog(@"moved numberOfTouchesRequired of touches:%ld", [gesture numberOfTouchesRequired]); 

} 

我仍然可以登錄:

2015-05-11 14:25:46.117 DroneG2[7521:1149008] === long press changed === 
2015-05-11 14:25:46.118 DroneG2[7521:1149008] moved guesture.number of touches:1 
2015-05-11 14:25:46.118 DroneG2[7521:1149008] moved numberOfTouchesRequired of touches:1 

有任何人都知道我的代碼在哪裏?

我想在移動時獲取其他手指觸摸點或事件嗎?

或者有其他方法可以實現多點觸控座標序列嗎?

非常感謝。

+0

確保您輕按兩次爲panelLongDoublePressGestureRecognizer獲取事件。 – Arvind

+0

我不知道爲什麼,當我在屏幕上移動手指時,然後用其他手指點擊屏幕,即不進入panelLongDoublePressGestureRecognizer。你知道爲什麼嗎? – dickfala

+0

用戶必須在視圖上按下一個或多個手指,並在觸發操作之前將其保持在那裏至少一段時間。下來時,用戶的手指可能不會移動超過指定的距離;如果他們移動超出指定距離,則手勢失敗。 https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UILongPressGestureRecognizer_Class/index.html – Arvind

回答

0

對於複雜的觸摸事件使用UIResponder的 方法..

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; 
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; 
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; 
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event; 

計算和區分觸摸事件。

Apple Doc for multitouch

+0

我的問題是從http://stackoverflow.com/questions/30117145/ios-multitouch-event-in-different-uiview/30117970?noredirect=1#comment48371038_30117970擴展。我正在使用touchesBegan orininal。 – dickfala

+0

當我使用了touchMoved時,它會延遲。你可以在這裏看到我的問題:http://stackoverflow.com/questions/30181332/how-to-resolve-touchesmoved-lag-in-ios – dickfala

相關問題