1

When the UIWebView displays the keyboard, there is a small toolbar at the top (accessory item) that has the buttons "done, previous, next"

Currently, I'm using the following as a workaround to remove this toolbar:

https://gist.github.com/2048571

However, I'm concerned this might not work in future version of iOS. Is there a better way to be doing this?

marklar
  • 502
  • 7
  • 21
  • Unfortunately, I'm still using this method. – marklar May 03 '12 at 22:39
  • I try the method you post here, but it doesnt work on ios 4.3. I found this one: http://stackoverflow.com/questions/8470984/how-to-remove-prev-next-button-from-virtual-keyboard-ios/8682238#comment13460308_8682238 it works well in iOS 4.3 and later. – jAckOdE May 04 '12 at 04:33
  • Interesting, I've got this method working in iOS5. I may have tweaked a few lines, I can try to figure out what I did if you're interested. – marklar May 04 '12 at 06:04

1 Answers1

1

First, listen keyboard events:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

when keyboard will show,remove the toolbar:

- (void)keyboardWillShow:(NSNotification *)note {
[self performSelector:@selector(removeBar) withObject:nil afterDelay:0];
}

the removeBar is as follows:

- (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 *possibleFormView in [keyboardWindow subviews]) {
        if ([[possibleFormView description] hasPrefix:@"<UIPeripheralHostView"]) {
            for (UIView* peripheralView in [possibleFormView subviews]) {

                // hides the backdrop (iOS 7)
                if ([[peripheralView description] hasPrefix:@"<UIKBInputBackdropView"]) {
                    //skip the keyboard background....hide only the toolbar background
                    if ([peripheralView frame].origin.y == 0){
                        [[peripheralView layer] setOpacity:0.0];
                    }
                }
                // hides the accessory bar
                if ([[peripheralView description] hasPrefix:@"<UIWebFormAccessory"]) {
                    // remove the extra scroll space for the form accessory bar
                    UIScrollView *webScroll;
                    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
                        webScroll = [[self webView] scrollView];
                    } else {
                        webScroll = [[[self webView] subviews] lastObject];
                    }
                    CGRect newFrame = webScroll.frame;
                    newFrame.size.height += peripheralView.frame.size.height;
                    webScroll.frame = newFrame;

                    // remove the form accessory bar
                    [peripheralView removeFromSuperview];
                }
                // hides the thin grey line used to adorn the bar (iOS 6)
                if ([[peripheralView description] hasPrefix:@"<UIImageView"]) {
                    [[peripheralView layer] setOpacity:0.0];
                }
            }
        }
    }
}

Reference: https://github.com/don/KeyboardToolbarRemover/blob/master/src/ios/KeyboardToolbarRemover.m

Yang Peiyong
  • 11,536
  • 2
  • 21
  • 15
  • This is using the private APIs, so there is chance that apple might not approve this, also it might get removed in future by apple as it is already mentioned in question itself. – Mehul Thakkar Nov 14 '18 at 12:27