Tap gesture fix

This commit is contained in:
TrueZhuanjia committed 2025-09-10 12:39:26 +08:00
1 parent 4e65abf6b1
commit 45acc28384
2 files changed
+30 -15

No files matched your search

+30 -12
View File
@@ -42,10 +42,11 @@ static CGFloat screenWidthInPoints;
if ([[event allTouches] count] == _numberOfTouchesRequired) { if ([[event allTouches] count] == _numberOfTouchesRequired) {
_gestureCapturedTime = CACurrentMediaTime(); _gestureCapturedTime = CACurrentMediaTime();
_gestureCaptured = true; _gestureCaptured = true;
lowestTouchPointYCoord = 0;
for(UITouch *touch in [event allTouches]){ for(UITouch *touch in [event allTouches]){
if(lowestTouchPointYCoord < [touch locationInView:self.view].y) lowestTouchPointYCoord = [touch locationInView:self.view].y; if(lowestTouchPointYCoord < [touch locationInView:self.view].y) lowestTouchPointYCoord = [touch locationInView:self.view].y;
// NSLog(@"lowest point coord: %f, %f", lowestTouchPointYCoord, CACurrentMediaTime());
} }
// this mechanism is deprecated. // this mechanism is deprecated.
/* if(_numberOfTouchesRequired == 2){ /* if(_numberOfTouchesRequired == 2){
NSArray *twoTouches = [[event allTouches] allObjects]; NSArray *twoTouches = [[event allTouches] allObjects];
@@ -55,7 +56,7 @@ static CGFloat screenWidthInPoints;
_lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord; _lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord;
// NSLog(@"gen _lowestTouchPointHeight %f markmark", _lowestTouchPointHeight); // NSLog(@"gen _lowestTouchPointHeight %f markmark", _lowestTouchPointHeight);
if(_immediateTriggering){ if(_immediateTriggering){
lowestTouchPointYCoord = 0.0; //reset for next recoginition // lowestTouchPointYCoord = 0.0; //reset for next recoginition
self.state = UIGestureRecognizerStateRecognized; self.state = UIGestureRecognizerStateRecognized;
return; return;
} }
@@ -69,11 +70,6 @@ static CGFloat screenWidthInPoints;
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
// [super touchesEnded:touches withEvent:event]; // [super touchesEnded:touches withEvent:event];
if(OnScreenWidgetView.tapGestureShallBeCancelled){
self.state = UIGestureRecognizerStateFailed;
OnScreenWidgetView.tapGestureShallBeCancelled = false;
return;
}
if(_immediateTriggering) return; if(_immediateTriggering) return;
uint8_t allTouchesCount = [[event allTouches] count]; uint8_t allTouchesCount = [[event allTouches] count];
@@ -81,18 +77,40 @@ static CGFloat screenWidthInPoints;
_gestureCaptured = false; _gestureCaptured = false;
self.state = UIGestureRecognizerStateFailed; self.state = UIGestureRecognizerStateFailed;
} }
else if(_gestureCaptured && allTouchesCount == [touches count] && !_isOnScreenControllerBeingPressed){ //must exclude virtual controller & onscreen button taps here to prevent stucked button, _areVirtualControllerTaps flag is set by onscreencontrols, containOnScreenButtonsTaps will be returned by iterating all widget views in streamframeview else if(_gestureCaptured && allTouchesCount == [touches count] && !_isOnScreenControllerBeingPressed && ![self isOnScreenWidgetViewBeingPressed]){ //must exclude virtual controller & onscreen button taps here to prevent stucked button, _areVirtualControllerTaps flag is set by onscreencontrols, containOnScreenButtonsTaps will be returned by iterating all widget views in streamframeview
_gestureCaptured = false; //reset for next recognition _gestureCaptured = false; //reset for next recognition
if((CACurrentMediaTime() - _gestureCapturedTime) < _tapDownTimeThreshold){ if((CACurrentMediaTime() - _gestureCapturedTime) < _tapDownTimeThreshold){
lowestTouchPointYCoord = 0.0; //reset for next recognition // lowestTouchPointYCoord = 0.0; //reset for next recognition
self.state = UIGestureRecognizerStateRecognized; self.state = UIGestureRecognizerStateRecognized;
// NSLog(@"gen _lowestTouchPointHeight %f markmark touchesEnd", _lowestTouchPointHeight); // NSLog(@"gen _lowestTouchPointHeight %f markmark touchesEnd", _lowestTouchPointHeight);
} }
} }
if (allTouchesCount == [touches count]){ if (allTouchesCount == [touches count]) _isOnScreenControllerBeingPressed = false; // need to reset this flag anyway, when all fingers are lefting
_isOnScreenControllerBeingPressed = false; // need to reset this flag anyway, when all fingers are lefting }
OnScreenWidgetView.tapGestureShallBeCancelled = false;
// it was a not a perfect choice to code OnScreenWidgetView in Swift...
// we're unable to import this class to swift codebase by the bridging header,and have to exlucde the onscreen button taps here
// by iterating every widget view instances. but it's basically ok since the number of widgetViews are always limited.
// and this method will only be called when the recognizer is active & and the taps passes all the checks and is about to ge triggered.
- (bool)isOnScreenWidgetViewBeingPressed {
NSTimeInterval allFingersTapDownTime = CACurrentMediaTime() - _gestureCapturedTime; //RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S has been passed to this recognizer as _tapDownTimeShreshold, we'll decide how to deal with pressed flag of on-screen widget views based on tapDownTime
bool gotOneWidgetPressed = false;
// the tap gestures are all added to the streamFrameTopLayerView, where all the OnScreenWidgetViews are added. so we can iterate them in this way:
for(UIView* view in self.view.subviews){
if ([view isKindOfClass:[OnScreenWidgetView class]]) {
OnScreenWidgetView* widgetView = (OnScreenWidgetView*) view;
if(gotOneWidgetPressed && allFingersTapDownTime <= _tapDownTimeThreshold){ // once we have just 1 button pressed already,& the tapDownTime has not exceeded the threshold, we'll reset pressed flag for the all the widgetViews.
widgetView.pressed = false; //reset the flag for widgetView
continue;
}
if(widgetView.pressed){
gotOneWidgetPressed = true; //got one button pressed
if(allFingersTapDownTime <= _tapDownTimeThreshold) widgetView.pressed = false; // reset the flag for current widgetView if tapDowntime is still within the threshold, if not, leave the flag for mouse scroller gesture in relative touch mode.
}
}
} }
return gotOneWidgetPressed;
} }
@end @end
-3
View File
@@ -31,8 +31,6 @@ import UIKit
case touchPad case touchPad
} }
@objc static public var tapGestureShallBeCancelled: Bool = false
@objc public var widgetType: WidgetTypeEnum = WidgetTypeEnum.uninitialized @objc public var widgetType: WidgetTypeEnum = WidgetTypeEnum.uninitialized
@objc static public var editMode: Bool = false @objc static public var editMode: Bool = false
@@ -1190,7 +1188,6 @@ import UIKit
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.touchBegan = true self.touchBegan = true
self.firstTouchMoved = false self.firstTouchMoved = false
OnScreenWidgetView.tapGestureShallBeCancelled = true
super.touchesBegan(touches, with: event) super.touchesBegan(touches, with: event)
// self.isMultipleTouchEnabled = self.touchPadString == "MOUSEPAD" // only enable multi-touch in mousePad mode // self.isMultipleTouchEnabled = self.touchPadString == "MOUSEPAD" // only enable multi-touch in mousePad mode
self.isMultipleTouchEnabled = self.widgetType == WidgetTypeEnum.button self.isMultipleTouchEnabled = self.widgetType == WidgetTypeEnum.button