7

I can remove the toolbar but I am left width a blur of the height the toolbar was.

Any idea on how to remove this?

The code below is the function. It's pretty straight forward. I use this in a webview using phonegap.

-(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]) {
        // iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
        if ([
            [possibleFormView description] rangeOfString: @"UIPeripheralHostView"].location != NSNotFound) {

            // remove the border above the toolbar in iOS 6
            [
                [possibleFormView layer] setMasksToBounds: YES];

            for (UIView * subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
                if ([
                    [subviewWhichIsPossibleFormView description] rangeOfString: @"UIWebFormAccessory"].location != NSNotFound) {
                    [subviewWhichIsPossibleFormView removeFromSuperview];

                    // http://stackoverflow.com/questions/10746998/phonegap-completely-removing-the-black-bar-from-the-iphone-keyboard/10796550#10796550
                    UIScrollView * webScroll;
                    if ([
                        [
                            [UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
                        webScroll = [
                            [self webView] scrollView];
                    } else {
                        webScroll = [
                            [
                                [self webView] subviews] lastObject];
                    }

                    CGRect newFrame = [webScroll frame];

                    float accessoryHeight = [subviewWhichIsPossibleFormView frame].size.height;
                    newFrame.size.height += accessoryHeight;

                    [subviewWhichIsPossibleFormView removeFromSuperview];
                    [webScroll setFrame: newFrame];
                }
            }
        }
    }
}

problem problem

If you hit this problem, make sure to head over to https://bugreport.apple.com and duplicate rdar://9844216

Mo.
  • 26,306
  • 36
  • 159
  • 225
Steeve17
  • 492
  • 6
  • 19
  • 3
    I have added the screenie :-) – Steeve17 Sep 17 '13 at 13:55
  • Have you tested your app on iPhone 5s with this code? Is it working fine? – Vishal Oct 07 '14 at 04:03
  • I found the solution for iOS 8. You can check it here: [ iOS 8 - Remove Previous/Next/Done UIKeyboard Toolbar inside a UIWebView][1] [1]: http://stackoverflow.com/questions/25022089/remove-next-previous-buttons-inputaccessoryview-for-custom-keyboard-in-ios8 – Gaurav Dec 03 '14 at 09:21
  • I found the solution for iOS 8. You can check it here: iOS 8 - Remove Previous/Next/Done UIKeyboard Toolbar inside a UIWebView http://stackoverflow.com/questions/25022089/remove-next-previous-buttons-inputaccessoryview-for-custom-keyboard-in-ios8 – Gaurav Dec 03 '14 at 09:28

3 Answers3

5
- (void)removeKeyboardTopBar {
// 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) {

            // HERE!! hides the backdrop (iOS 7)
            if ([[peripheralView description] hasPrefix:@"<UIKBInputBackdropView"]) {
                [[peripheralView layer] setOpacity:0.0];
            }
            // hides the accessory bar
            if ([[peripheralView description] hasPrefix:@"<UIWebFormAccessory"]) {
                // remove the extra scroll space for the form accessory bar
                CGRect newFrame = diaryEditorView.scrollView.frame;
                newFrame.size.height += peripheralView.frame.size.height;
                diaryEditorView.scrollView.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];
            }
        }
    }
}

}

  • 4
    good answer. It can be improved though. There are two backdrop views: one under the form toolbar, the other under the keyboard itself. Your solution hides both backdrop views. As a result, the keyboard becomes transparent -- an undesirable side effect. I would modify your solution a bit: hide only the backdrop under the toolbar (its `y` coordinate is 0). For example, `CGRect rect = peripheralView.frame; if (rect.origin.y == 0) [[peripheralView layer] setOpacity:0.0];` – Alexander Poleschuk Sep 29 '13 at 21:03
  • I still have a white or black background depending on the color of the webview. I think the webview does not get resized to the correct size. – Steeve17 Oct 16 '13 at 14:48
  • This will work on any phonegap version only if the viewport meta height=device-height is set – Steeve17 Oct 18 '13 at 13:52
  • Alexander's origin.y check worked well for me. This appears to be especially important on iOS 7.1. – Andy Arvanitis Mar 12 '14 at 02:36
  • ios noob here. does anyone know how to fix the "Use of undeclared identifier 'diaryEditorView'" error? thanks – Sergio Morstabilini Jun 13 '14 at 07:33
  • @user2038156: This code is not working in iPhone 5s with iOS8. Do you have any suggestion that the code is also working in iPhone 5s? – Vishal Oct 07 '14 at 03:58
1

User2038156's answer did not worked well for me on 7.1 because it also excludes the panel behind the keyboard, making it completely transparent. To remove only the background of the extra area you can use this code:

- (void)removeBar {
    if(self.isHidingDoneBar){
        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) {

                    // HERE!! hides the backdrop (iOS 7)
                    if ([[peripheralView description] hasPrefix:@"<UIKBInputBackdropView"] && peripheralView.frame.size.height == 44) {
                        [[peripheralView layer] setOpacity:0.0];
                    }
                    // hides the accessory bar
                    if ([[peripheralView description] hasPrefix:@"<UIWebFormAccessory"]) {
                        // remove the extra scroll space for the form accessory bar
                        CGRect newFrame = webView.scrollView.frame;
                        newFrame.size.height += peripheralView.frame.size.height;
                        webView.scrollView.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];
                    }
                }
            }
        }
    }
}
0

Here is a good quick way to accomplish the same in swift with only one line of code, done inside your custom UIResponder :

public override func becomeFirstResponder() -> Bool {

     if !self.isEditing {

            super.becomeFirstResponder()
            //TODO: Do some sanity checks here , this is a hack to remove the backdrop on iOS 7.0 +
            self.inputView?.superview?.subviews.first?.removeFromSuperview()

     }
}
John
  • 61
  • 1
  • 2