Skip to content

Instantly share code, notes, and snippets.

@daviddulak
Last active December 25, 2015 12:28
Show Gist options
  • Save daviddulak/6976193 to your computer and use it in GitHub Desktop.
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.
- (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