Last active
December 25, 2015 12:28
-
-
Save daviddulak/6976193 to your computer and use it in GitHub Desktop.
A way to notify a PhoneGap webview when the keyboard shows or hides and include the keyboard height. Should be placed in MainViewController.m for use with PhoneGap.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)keyboardWillShowOrHide:(NSNotification*)notif | |
{ | |
CGRect keyboardFrame = [notif.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; | |
keyboardFrame = [self.view convertRect:keyboardFrame fromView:nil]; | |
CGFloat height = keyboardFrame.size.height; | |
BOOL showing = [notif.name isEqualToString:UIKeyboardWillShowNotification]; | |
NSString *showingString = showing ? @"true" : @"false"; | |
NSString *jsString = [NSString stringWithFormat:@"$(window).trigger(jQuery.Event('keyboardToggle', {showing: %@, height: %f}));", showingString, height]; | |
[self.webView stringByEvaluatingJavaScriptFromString:jsString]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment