Implement view lifting for keyboard invoke.

This commit is contained in:
True Zhuanjia
2024-05-26 00:03:00 +08:00
parent 6b48083ad9
commit d54205dec8
5 changed files with 39 additions and 7 deletions
@@ -15,6 +15,8 @@
@property (nonatomic, assign) uint8_t numberOfTouchesRequired;
@property (nonatomic, assign) double tapDownTimeThreshold;
@property (nonatomic, readonly) CGFloat lowestTouchPointHeight;
@end
#endif /* CustomTapGestureRecognizer_h */
+14 -1
View File
@@ -14,9 +14,12 @@
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]);
return self;
}
@@ -25,15 +28,25 @@ static bool multiFingerDown;
if ([[event allTouches] count] == _numberOfTouchesRequired) {
multiFingerDownTime = CACurrentMediaTime();
multiFingerDown = true;
for(UITouch *touch in [event allTouches]){
if(lowestTouchPointYCoord < [touch locationInView:self.view].y) lowestTouchPointYCoord = [touch locationInView:self.view].y;
}
//NSLog(@"lowestTouchPointYCoord: %f ", lowestTouchPointYCoord);
_lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord;
self.state = UIGestureRecognizerStatePossible;
}
}
- (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) self.state = UIGestureRecognizerStateRecognized;
if((CACurrentMediaTime() - multiFingerDownTime) < _tapDownTimeThreshold / 1000){
lowestTouchPointYCoord = 0.0; //reset for next recognition
self.state = UIGestureRecognizerStateRecognized;
}
}
}
+21 -4
View File
@@ -49,6 +49,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
NSDictionary<NSString *, NSNumber *> *dictCodes;
CustomTapGestureRecognizer *keyboardToggleRecognizer;
CGFloat liftViewToHeight;
}
- (void) setupStreamView:(ControllerSupport*)controllerSupport
@@ -76,12 +77,12 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
keyboardToggleRecognizer.delaysTouchesBegan = NO;
keyboardToggleRecognizer.delaysTouchesEnded = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow)
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide)
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
[self addGestureRecognizer:keyboardToggleRecognizer];
@@ -152,12 +153,27 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
[self becomeFirstResponder];
}
- (void)keyboardWillShow{
- (void)keyboardWillShow:(NSNotification *)notification{
NSDictionary *userInfo = notification.userInfo;
// Get the keyboard size from the notification
CGRect keyboardFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
liftViewToHeight = keyboardFrame.size.height - keyboardToggleRecognizer.lowestTouchPointHeight + CGRectGetHeight([[UIScreen mainScreen] bounds]) * 0.1; // lift the StreamView to the height of lowest touch point of multi-finger tap gesture, while reserving the view of 1/10 screen height for remote typing.
if(liftViewToHeight < 0) liftViewToHeight = 0; // set liftViewtoHeight to 0 if it is high enough and not going to be covered by keyboard.
CGRect liftedStreamFrame = self.frame;
liftedStreamFrame.origin.y -= liftViewToHeight;
self.frame = liftedStreamFrame;
isInputingText = true;
// NSLog(@"keyboard will show");
}
- (void)keyboardWillHide{
- (void)keyboardWillHide:(NSNotification *)notification{
CGRect liftedStreamFrame = self.frame;
// recover view position in keyboard hiding.
liftedStreamFrame.origin.y += liftViewToHeight;
self.frame = liftedStreamFrame;
isInputingText = false;
// NSLog(@"keyboard will hide");
}
@@ -170,6 +186,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
[keyInputField resignFirstResponder];
isInputingText = false;
} else {
// NSLog(@"Opening the keyboard");
Log(LOG_D, @"Opening the keyboard");
// Prepare the textbox used to capture keyboard events.
+1 -1
View File
@@ -9,7 +9,7 @@
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>Moonlight-ZWM</string>
<string>Moonlight-ZWM-Debug</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
+1 -1
View File
@@ -5,7 +5,7 @@
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Moonlight-ZWM</string>
<string>Moonlight-ZWM-Debug</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>