2

I have tried the following code from another application but it doesn't find anything. Why? How to get access to the UIWebView toolbar?

- (UIToolbar *)findVirginWebKeyboardToolbar:(UIView *)parent
{
    if ([parent isKindOfClass:[UIToolbar class]]) {
        UIToolbar *tb = (UIToolbar *)parent;
        if ([tb.items count] == 1 && [((UIBarButtonItem *)[tb.items objectAtIndex:0]).customView isKindOfClass:[UISegmentedControl class]]) {
            return tb;
        }
    }
    for (UIView *view in parent.subviews) {
        UIToolbar *tb = [self findVirginWebKeyboardToolbar:view];
        if (tb) return tb;
    }
    return nil;
}

- (void)removeKeyboardBar {
    UIView *keyboardWindow = nil;
    for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
        keyboardWindow = testWindow;
        UIToolbar *toolbar = [self findVirginWebKeyboardToolbar:keyboardWindow/*subviewWhichIsPossibleFormView*/];
        if (toolbar) {
            itemsArray = [NSArray arrayWithObjects:button1, button2, button3, nil];
            [toolbar setItems:itemsArray];
        }
    }
}
Dmitry
  • 14,306
  • 23
  • 105
  • 189

1 Answers1

6

With the following code you should be able to remove the toolbar that is above the keyboard.

-(void)viewWillAppear:(BOOL)animated{
  [[NSNotificationCenter defaultCenter] addObserver:self
                                        selector:@selector(keyboardWillShow:)
                                            name:UIKeyboardWillShowNotification
                                          object:nil];
}

- (void)keyboardWillShow:(NSNotification *)note {
  [self performSelector:@selector(removeBar) withObject:nil afterDelay:0];
}
- (void)removeBar {
 // Locate non-UIWindow.
 UIWindow *keyboardWindow = nil;
 for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
 if (![[testWindow class] isEqual:[UIWindow class]]) {
    keyboardWindow = testWindow;
    break;
 }
}
  // Locate UIWebFormView.
  for (UIView *formView in [keyboardWindow subviews]) {
  // iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
  if ([[formView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) {
    for (UIView *subView in [formView subviews]) {
        if ([[subView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) {
            // remove the input accessory view
            [subView removeFromSuperview];
        }
        else if([[subView description] rangeOfString:@"UIImageView"].location != NSNotFound){
            // remove the line above the input accessory view (changing the frame)
            [subView setFrame:CGRectZero];
        }
    }
  }
}
}
oiledCode
  • 8,589
  • 6
  • 43
  • 59
  • It's also possible to find UIScrollView inside the UIWebView and to resize it correctly to hide empty space on the bottom. – Dmitry Nov 05 '12 at 14:29
  • @Altaveron - I'm trying to find UIScrollView inside the UIWebView and to resize it correctly to hide empty space on the bottom but no success. Can you suggest me any idea please? – alloc_iNit Jun 04 '13 at 11:00
  • to find the scrollView you don't need all this stuff, the webview expose a property scrollView that gives you access to the webview's scrollView – oiledCode Jun 05 '13 at 12:27
  • In iOS 7, things are a bit different. [This solution](http://stackoverflow.com/questions/18837551/remove-keyboard-form-toolbar-on-ios7-leaves-a-blur-behind/19042392#19042392) works both for iOS 6 and iOS 7. – Alexander Poleschuk Sep 29 '13 at 21:10