Right click gesture & scroll gesture improvement in relative touch (trackpad) mode;
CustomTapGestureRecognizer improvement.
This commit is contained in:
1 parent
c6785e3728
commit
ec4299fd88
4 files changed
+50
-19
No files matched your search
@@ -12,46 +12,48 @@
|
||||
|
||||
@implementation CustomTapGestureRecognizer
|
||||
|
||||
static NSTimeInterval multiFingerDownTime;
|
||||
static bool multiFingerDown;
|
||||
static CGFloat screenHeightInPoints;
|
||||
static CGFloat lowestTouchPointYCoord = 0.0;
|
||||
|
||||
- (instancetype)initWithTarget:(nullable id)target action:(nullable SEL)action {
|
||||
self = [super initWithTarget:target action:action];
|
||||
screenHeightInPoints = CGRectGetHeight([[UIScreen mainScreen] bounds]);
|
||||
lowestTouchPointYCoord = 0.0;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
||||
// Check if the number of touches and taps meets the required criteria
|
||||
if ([[event allTouches] count] == _numberOfTouchesRequired) {
|
||||
multiFingerDownTime = CACurrentMediaTime();
|
||||
multiFingerDown = true;
|
||||
|
||||
_gestureCapturedTime = CACurrentMediaTime();
|
||||
_gestureCaptured = true;
|
||||
for(UITouch *touch in [event allTouches]){
|
||||
if(lowestTouchPointYCoord < [touch locationInView:self.view].y) lowestTouchPointYCoord = [touch locationInView:self.view].y;
|
||||
}
|
||||
_lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord;
|
||||
self.state = UIGestureRecognizerStatePossible;
|
||||
}
|
||||
if ([[event allTouches] count] > _numberOfTouchesRequired) {
|
||||
_gestureCaptured = false;
|
||||
self.state = UIGestureRecognizerStateFailed;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
||||
// [super touchesEnded:touches withEvent:event];
|
||||
if(multiFingerDown && [[event allTouches] count] == [touches count]){
|
||||
multiFingerDown = false;
|
||||
if((CACurrentMediaTime() - multiFingerDownTime) < _tapDownTimeThreshold / 1000){
|
||||
if(_gestureCaptured && [[event allTouches] count] == [touches count]){
|
||||
_gestureCaptured = false;
|
||||
if((CACurrentMediaTime() - _gestureCapturedTime) < _tapDownTimeThreshold){
|
||||
lowestTouchPointYCoord = 0.0; //reset for next recognition
|
||||
self.state = UIGestureRecognizerStateRecognized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
+ (CGFloat)lowestTouchPointHeight{
|
||||
@synchronized (self){
|
||||
return self.lowestTouchPointHeight;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user