fix view lift not working on first keyboard invoke.

This commit is contained in:
True Zhuanjia committed 2024-05-27 21:06:48 +08:00
1 parent 746479d359
commit e5fa7f9c72
3 files changed
+17 -20

No files matched your search

+1 -1
View File
@@ -15,7 +15,7 @@
@property (nonatomic, assign) uint8_t numberOfTouchesRequired; @property (nonatomic, assign) uint8_t numberOfTouchesRequired;
@property (nonatomic, assign) double tapDownTimeThreshold; @property (nonatomic, assign) double tapDownTimeThreshold;
@property (nonatomic, readonly) CGFloat lowestTouchPointHeight; @property (atomic, readonly) CGFloat lowestTouchPointHeight;
@end @end
+6 -2
View File
@@ -32,14 +32,12 @@ static CGFloat lowestTouchPointYCoord = 0.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(@"lowestTouchPointYCoord: %f ", lowestTouchPointYCoord);
_lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord; _lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord;
self.state = UIGestureRecognizerStatePossible; self.state = UIGestureRecognizerStatePossible;
} }
} }
- (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(multiFingerDown && [[event allTouches] count] == [touches count]){ if(multiFingerDown && [[event allTouches] count] == [touches count]){
multiFingerDown = false; multiFingerDown = false;
@@ -50,4 +48,10 @@ static CGFloat lowestTouchPointYCoord = 0.0;
} }
} }
+ (CGFloat)lowestTouchPointHeight{
@synchronized (self){
return self.lowestTouchPointHeight;
}
}
@end @end
+10 -17
View File
@@ -51,7 +51,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
NSDictionary<NSString *, NSNumber *> *dictCodes; NSDictionary<NSString *, NSNumber *> *dictCodes;
CustomTapGestureRecognizer *keyboardToggleRecognizer; CustomTapGestureRecognizer *keyboardToggleRecognizer;
CGFloat liftViewToHeight; CGFloat HeightViewLiftedTo;
} }
- (void) setupStreamView:(ControllerSupport*)controllerSupport - (void) setupStreamView:(ControllerSupport*)controllerSupport
@@ -156,34 +156,32 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
[self becomeFirstResponder]; [self becomeFirstResponder];
} }
- (void)keyboardWillShow:(NSNotification *)notification{ - (void)keyboardWillShow:(NSNotification *)notification{
if(settings.liftStreamViewForKeyboard && !isInputingText){ if(settings.liftStreamViewForKeyboard && !isInputingText){
NSDictionary *userInfo = notification.userInfo; NSDictionary *userInfo = notification.userInfo;
// Get the keyboard size from the notification // Get the keyboard size from the notification
CGRect keyboardFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; 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. // NSLog(@"keyboard height %f, lowest point height %f", keyboardFrame.size.height, keyboardToggleRecognizer.lowestTouchPointHeight);
if(liftViewToHeight < 0) liftViewToHeight = 0; // set liftViewtoHeight to 0 if it is high enough and not going to be covered by keyboard. if(keyboardFrame.size.height < CGRectGetHeight([[UIScreen mainScreen] bounds]) * 0.25) return; // return in case of abnormal keyboard height
HeightViewLiftedTo = 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(HeightViewLiftedTo < 0) HeightViewLiftedTo = 0; // set HeightViewLiftedTo to 0 if it is high enough and not going to be covered by keyboard.
CGRect liftedStreamFrame = self.frame; CGRect liftedStreamFrame = self.frame;
liftedStreamFrame.origin.y -= liftViewToHeight; liftedStreamFrame.origin.y -= HeightViewLiftedTo;
self.frame = liftedStreamFrame; self.frame = liftedStreamFrame;
}
isInputingText = true; isInputingText = true;
}
// NSLog(@"keyboard will show"); // NSLog(@"keyboard will show");
} }
- (void)keyboardWillHide:(NSNotification *)notification{ - (void)keyboardWillHide:(NSNotification *)notification{
if(settings.liftStreamViewForKeyboard && isInputingText){ if(isInputingText){
CGRect liftedStreamFrame = self.frame; CGRect liftedStreamFrame = self.frame;
// recover view position in keyboard hiding. // recover view position in keyboard hiding.
liftedStreamFrame.origin.y += liftViewToHeight; liftedStreamFrame.origin.y += HeightViewLiftedTo;
self.frame = liftedStreamFrame; self.frame = liftedStreamFrame;
}
isInputingText = false; isInputingText = false;
}
// NSLog(@"keyboard will hide"); // NSLog(@"keyboard will hide");
} }
@@ -191,12 +189,8 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
- (void)toggleKeyboard{ - (void)toggleKeyboard{
if (isInputingText) { if (isInputingText) {
Log(LOG_D, @"Closing the keyboard"); Log(LOG_D, @"Closing the keyboard");
// NSLog(@"Closing the keyboard");
[keyInputField resignFirstResponder]; [keyInputField resignFirstResponder];
isInputingText = false;
} else { } else {
// NSLog(@"Opening the keyboard");
Log(LOG_D, @"Opening the keyboard"); Log(LOG_D, @"Opening the keyboard");
// Prepare the textbox used to capture keyboard events. // Prepare the textbox used to capture keyboard events.
keyInputField.delegate = self; keyInputField.delegate = self;
@@ -223,7 +217,6 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
[keyInputField addTarget:self action:@selector(onKeyboardPressed:) forControlEvents:UIControlEventEditingChanged]; [keyInputField addTarget:self action:@selector(onKeyboardPressed:) forControlEvents:UIControlEventEditingChanged];
// Undo causes issues for our state management, so turn it off // Undo causes issues for our state management, so turn it off
[keyInputField.undoManager disableUndoRegistration]; [keyInputField.undoManager disableUndoRegistration];
//isInputingText = true;
} }
} }