Native touch oriented improvements
This commit is contained in:
1 parent
557765f2c0
commit
873269e410
25 files changed
+2254
-283
No files matched your search
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// CustomEdgeSwipeGestureRecognizer.m
|
||||
// Moonlight-ZWM
|
||||
//
|
||||
// Created by ZWM on 2024/4/30.
|
||||
// Copyright © 2024 Moonlight Game Streaming Project. All rights reserved.
|
||||
//
|
||||
|
||||
// #import <Foundation/Foundation.h>
|
||||
|
||||
#import "CustomEdgeSwipeGestureRecognizer.h"
|
||||
#import <UIKit/UIGestureRecognizerSubclass.h>
|
||||
|
||||
@implementation CustomEdgeSwipeGestureRecognizer
|
||||
UITouch* capturedUITouch;
|
||||
CGFloat _startPointX;
|
||||
static CGFloat screenWidthInPoints;
|
||||
static CGFloat EDGE_TOLERANCE_POINTS = 50.0f;
|
||||
|
||||
- (instancetype)initWithTarget:(nullable id)target action:(nullable SEL)action {
|
||||
self = [super initWithTarget:target action:action];
|
||||
screenWidthInPoints = CGRectGetWidth([[UIScreen mainScreen] bounds]); // Get the screen's bounds (in points)
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
||||
// [super touchesBegan:touches withEvent:event];
|
||||
UITouch *touch = [touches anyObject];
|
||||
capturedUITouch = touch;
|
||||
_startPointX = [capturedUITouch locationInView:self.view].x;
|
||||
}
|
||||
|
||||
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
||||
// [super touchesEnded:touches withEvent:event];
|
||||
|
||||
if([touches containsObject:capturedUITouch]){
|
||||
CGFloat _endPointX = [capturedUITouch locationInView:self.view].x;
|
||||
CGFloat normalizedGestureDistance = fabs(_endPointX - _startPointX)/screenWidthInPoints;
|
||||
|
||||
if(self.edges & UIRectEdgeLeft){
|
||||
if(_startPointX < EDGE_TOLERANCE_POINTS && normalizedGestureDistance > _normalizedThresholdDistance){
|
||||
self.state = UIGestureRecognizerStateBegan;
|
||||
self.state = UIGestureRecognizerStateEnded;
|
||||
}
|
||||
// NSLog(@"_startPointX %f , normalizedGestureDeltaX %f", _startPointX, normalizedGestureDistance);
|
||||
}
|
||||
if(self.edges & UIRectEdgeRight){
|
||||
if((_startPointX > (screenWidthInPoints - EDGE_TOLERANCE_POINTS)) && normalizedGestureDistance > _normalizedThresholdDistance){
|
||||
self.state = UIGestureRecognizerStateBegan;
|
||||
self.state = UIGestureRecognizerStateEnded;
|
||||
}
|
||||
// NSLog(@"_startPointX %f , normalizedGestureDeltaX %f", _startPointX, normalizedGestureDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user