Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2011
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(keyboardWasShown:) name:UIKeyboardAppearanceDefault object:nil];
  2.  
  3.  
  4.  
  5.  
  6. - (void)keyboardWasHidden:(NSNotification*)aNotification
  7. {
  8.  
  9.     [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(keyboardWasShown:) name:UIKeyboardAppearanceDefault object:nil];
  10.  
  11.    
  12.    [((PhoneGapDelegate*)[[UIApplication sharedApplication] delegate]).webView stringByEvaluatingJavaScriptFromString:@"document.getElementById(signal.currentPage).scrollIntoView();"];
  13. }
  14.  
  15.  
  16. - (void)keyboardWasShown:(NSNotification*)aNotification
  17. {
  18.     UIWindow* tempWindow;
  19.    
  20.     //Because we cant get access to the UIKeyboard throught the SDK we will just use UIView.
  21.     //UIKeyboard is a subclass of UIView anyways
  22.     UIView* keyboard;
  23.    
  24.     //Check each window in our application
  25.     for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; c ++)
  26.     {
  27.         //Get a reference of the current window
  28.         tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c];
  29.    
  30.         //Get a reference of the current view
  31.         for(int i = 0; i < [tempWindow.subviews count]; i++)
  32.         {
  33.             keyboard = [tempWindow.subviews objectAtIndex:i];
  34.             if([[keyboard description] hasPrefix:@"<UIPeripheralHostView"] == YES)
  35.             {  
  36.                 keyboard.hidden = YES;
  37.                 UIView* keyboardLayer;
  38.                 for(int n = 0; n < [keyboard.subviews count]; n++)
  39.                 {
  40.                     keyboardLayer = [keyboard.subviews objectAtIndex:n];
  41.                     NSLog(@" keyboardLayer ::: %@ " ,keyboardLayer);
  42.                     if([[keyboardLayer description] hasPrefix:@"<UIWebFormAccessory"] == YES)
  43.                     {
  44.                         [keyboardLayer removeFromSuperview ];
  45.                     }
  46.                 }
  47.                 keyboard.hidden = NO;
  48.                 [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardAppearanceDefault object:nil];
  49.                 [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(keyboardWasHidden:) name:UIKeyboardDidHideNotification object:nil];
  50.             }
  51.         }
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement