// // CustomTapGestureRecognizer.m // Moonlight // // Created by ZWM on 2024/5/15. // Copyright © 2024 Moonlight Game Streaming Project. All rights reserved. // #import #import #import "CustomTapGestureRecognizer.h" @implementation CustomTapGestureRecognizer static CGFloat screenHeightInPoints; - (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 *)touches withEvent:(UIEvent *)event { // Check if the number of touches and taps meets the required criteria if ([[event allTouches] count] == _numberOfTouchesRequired) { _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 *)touches withEvent:(UIEvent *)event { // [super touchesEnded:touches withEvent:event]; 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