Merge pull request #1633 from MicahChase/master

Bluetooth Keyboard Fix
This commit is contained in:
Martin Fleisz 2014-04-22 08:36:25 +02:00
commit 43e08997f1
2 changed files with 38 additions and 25 deletions

View File

@ -57,7 +57,7 @@
AdvancedKeyboardView* _advanced_keyboard_view; AdvancedKeyboardView* _advanced_keyboard_view;
BOOL _advanced_keyboard_visible; BOOL _advanced_keyboard_visible;
BOOL _requesting_advanced_keyboard; BOOL _requesting_advanced_keyboard;
CGFloat _keyboard_height_delta; CGFloat _keyboard_last_height;
// delayed mouse move event sending // delayed mouse move event sending
NSTimer* _mouse_move_event_timer; NSTimer* _mouse_move_event_timer;

View File

@ -51,7 +51,7 @@
_advanced_keyboard_view = nil; _advanced_keyboard_view = nil;
_advanced_keyboard_visible = NO; _advanced_keyboard_visible = NO;
_requesting_advanced_keyboard = NO; _requesting_advanced_keyboard = NO;
_keyboard_height_delta = 0; _keyboard_last_height = 0;
_session_toolbar_visible = NO; _session_toolbar_visible = NO;
@ -549,25 +549,46 @@
#pragma mark - #pragma mark -
#pragma mark iOS Keyboard Notification Handlers #pragma mark iOS Keyboard Notification Handlers
- (void)keyboardWillShow:(NSNotification *)notification // the keyboard is given in a portrait frame of reference
{ - (BOOL)isLandscape {
CGRect keyboardEndFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect keyboardFrame = [[self view] convertRect:keyboardEndFrame toView:nil]; UIInterfaceOrientation ori = [[UIApplication sharedApplication] statusBarOrientation];
return ( ori == UIInterfaceOrientationLandscapeLeft || ori == UIInterfaceOrientationLandscapeRight );
}
CGFloat newHeightDelta = (keyboardFrame.size.height - _keyboard_height_delta); - (void)shiftKeyboard: (NSNotification*)notification {
if (newHeightDelta < 0.1 && newHeightDelta > -0.1)
return; // nothing changed CGRect keyboardEndFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
[UIView beginAnimations:nil context:NULL]; CGFloat previousHeight = _keyboard_last_height;
if( [self isLandscape] ) {
// landscape has the keyboard based on x, so x can go negative
_keyboard_last_height = keyboardEndFrame.size.width + keyboardEndFrame.origin.x;
} else {
// portrait has the keyboard based on the difference of the height and the frames y.
CGFloat height = [[UIScreen mainScreen] bounds].size.height;
_keyboard_last_height = height - keyboardEndFrame.origin.y;
}
CGFloat shiftHeight = _keyboard_last_height - previousHeight;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]]; [UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
[UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]]; [UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
CGRect frame = [_session_scrollview frame]; CGRect frame = [_session_scrollview frame];
frame.size.height -= newHeightDelta; frame.size.height -= shiftHeight;
_keyboard_height_delta += newHeightDelta;
[_session_scrollview setFrame:frame]; [_session_scrollview setFrame:frame];
[_touchpointer_view setFrame:frame]; [_touchpointer_view setFrame:frame];
[UIView commitAnimations]; [UIView commitAnimations];
}
- (void)keyboardWillShow:(NSNotification *)notification
{
[self shiftKeyboard: notification];
[_touchpointer_view ensurePointerIsVisible]; [_touchpointer_view ensurePointerIsVisible];
} }
@ -583,17 +604,9 @@
- (void)keyboardWillHide:(NSNotification *)notification - (void)keyboardWillHide:(NSNotification *)notification
{ {
CGRect keyboardEndFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
[self shiftKeyboard: notification];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
[UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
CGRect frame = [_session_scrollview frame];
frame.size.height += [[self view] convertRect:keyboardEndFrame toView:nil].size.height;
[_session_scrollview setFrame:frame];
[_touchpointer_view setFrame:frame];
[UIView commitAnimations];
_keyboard_height_delta = 0;
} }
- (void)keyboardDidHide:(NSNotification*)notification - (void)keyboardDidHide:(NSNotification*)notification