resolve gesture competition in non-native touch modes
This commit is contained in:
1 parent
c3d44647f9
commit
c3c7e670fc
5 files changed
+27
-7
No files matched your search
@@ -10,8 +10,11 @@
|
||||
#import <UIKit/UIGestureRecognizerSubclass.h>
|
||||
#import "CustomTapGestureRecognizer.h"
|
||||
|
||||
// The most accurate & reliable tap gesture recognizer of iOS with almost 100% recoginition rate, instances of different numberOfTouchesRequired barely compete with each other. UITapGestureRecognizer of Apple API is just intractable.
|
||||
// Known issue: not reliable in absolute touch mode, since it competes with 2 finger zoom-in & out gestures from original moonlight
|
||||
// The most accurate & reliable tap gesture recognizer of iOS:
|
||||
// - almost 100% recoginition rate. UITapGestureRecognizer of Apple API is just intractable.
|
||||
// - instances of different numberOfTouchesRequired barely compete with each other, even when immediateTriggering is set to false.
|
||||
// - set property immediateTriggering = true, ensures no competition with gestures of less fingers in non-native touch mode.
|
||||
|
||||
@implementation CustomTapGestureRecognizer
|
||||
|
||||
static CGFloat screenHeightInPoints;
|
||||
@@ -20,6 +23,10 @@ static CGFloat screenHeightInPoints;
|
||||
self = [super initWithTarget:target action:action];
|
||||
screenHeightInPoints = CGRectGetHeight([[UIScreen mainScreen] bounds]);
|
||||
lowestTouchPointYCoord = 0.0;
|
||||
_numberOfTouchesRequired = 3;
|
||||
_immediateTriggering = false;
|
||||
_tapDownTimeThreshold = 0.3;
|
||||
_gestureCaptured = false;
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -32,6 +39,11 @@ static CGFloat screenHeightInPoints;
|
||||
if(lowestTouchPointYCoord < [touch locationInView:self.view].y) lowestTouchPointYCoord = [touch locationInView:self.view].y;
|
||||
}
|
||||
_lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord;
|
||||
if(_immediateTriggering){
|
||||
lowestTouchPointYCoord = 0.0; //reset for next recoginition
|
||||
self.state = UIGestureRecognizerStateRecognized;
|
||||
return;
|
||||
}
|
||||
self.state = UIGestureRecognizerStatePossible;
|
||||
}
|
||||
if ([[event allTouches] count] > _numberOfTouchesRequired) {
|
||||
@@ -42,7 +54,8 @@ static CGFloat screenHeightInPoints;
|
||||
|
||||
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
||||
// [super touchesEnded:touches withEvent:event];
|
||||
if ([[event allTouches] count] > _numberOfTouchesRequired) {
|
||||
if(_immediateTriggering) return;
|
||||
if([[event allTouches] count] > _numberOfTouchesRequired) {
|
||||
_gestureCaptured = false;
|
||||
self.state = UIGestureRecognizerStateFailed;
|
||||
} else if(_gestureCaptured && [[event allTouches] count] == [touches count]){
|
||||
|
||||
Reference in new issue
Block a user