3

In my program I use UIWebView with editable div for the Rich text editor. I need to remove top bar of the keyboard. enter image description here

I used below code - it removes only next/previous buttons I want to remove full top bar.

- (void)removeBar {
    UIWindow *keyboardWindow = nil;
    for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
        if (![[testWindow class] isEqual:[UIWindow class]]) {
            keyboardWindow = testWindow;
            break;
        }
    }

    for (UIView *possibleFormView in [keyboardWindow subviews]) {
        // iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
        if ([[possibleFormView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) {
            for (UIView *subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
                if ([[subviewWhichIsPossibleFormView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) {
                    [subviewWhichIsPossibleFormView removeFromSuperview];
                }
            }
        }
    }
}
Popeye
  • 11,839
  • 9
  • 58
  • 91
Suravi
  • 301
  • 1
  • 7
  • 21
  • 2
    To be honest I'm not sure Apple will allow you to go messing with the native keyboard like this. This may get rejected when submitted. – Popeye Nov 21 '13 at 14:59
  • That not appear for the textView and textField.i need without tool bar of the keyboard – Suravi Nov 21 '13 at 15:14
  • Messing with the keyboard in anyway has rejection written all over it even if it is just getting rid of the toolbar at the top of the keyboard. I would recommend reviewing your design plan because I really don't think this is allowed. Sorry. – Popeye Nov 21 '13 at 15:17
  • It doesn't work anymore on iOS8. – Dmitry Jun 05 '14 at 20:35
  • I found the solution for iOS 8. You can check it here:http://cocoainios.blogspot.in/2014/11/ios8-uiwebview-remove-or-modify.html – Saurav Nagpal Nov 11 '14 at 05:41
  • 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:23

3 Answers3

3

I found the solution for iOS 8. You can check it here: [ iOS 8 - Remove Previous/Next/Done UIKeyboard Toolbar inside a UIWebView][1]

You may try and improve this. try call this function inside Your UIKeyboardDidShowNotification event handler.

Hope this helps... This is the level of views in accessory: (UIWebFormAccessory) -> (UIToolbar) -> (UIImageView,UIToolbarButton,UIToolbarButton)

-(void) removeKeyboard {
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 : @"<UIInputSetContainerView"]) {
        for (UIView* peripheralView in possibleFormView.subviews) {

            for (UIView* peripheralView_sub in peripheralView.subviews) {


                // hides the backdrop (iOS 8)
                if ([[peripheralView_sub description] hasPrefix : @"<UIKBInputBackdropView"] && peripheralView_sub.frame.size.height == 44) {
                    [[peripheralView_sub layer] setOpacity : 0.0];

                }
                // hides the accessory bar
                if ([[peripheralView_sub description] hasPrefix : @"<UIWebFormAccessory"]) {


                    for (UIView* UIInputViewContent_sub in peripheralView_sub.subviews) {

                        CGRect frame1 = UIInputViewContent_sub.frame;
                        frame1.size.height = 0;
                        peripheralView_sub.frame = frame1;
                        UIInputViewContent_sub.frame = frame1;
                        [[peripheralView_sub layer] setOpacity : 0.0];

                    }

                    CGRect viewBounds = peripheralView_sub.frame;
                    viewBounds.size.height = 0;
                    peripheralView_sub.frame = viewBounds;

                }
            }

        }
    }


}
}
Gaurav
  • 168
  • 12
0

From what I can tell, it looks like the keyboard has an added inputAccessoryView to the top of it. Otherwise, I'm not certain why it is appearing. Anyways, if that is the case then whatever you assign firstResponder to set their inputAccessoryView to nil:

someObjectWithFirstResponder.inputAccessoryView = nil;

EDIT: Looks like the UIWebView sets the inputAccessoryView itself, but if it is actually receiving firstResponder then you should be able to override the inputAccessoryView. If setting it to nil causing it to default back to the inputAccessoryView that you are trying to remove, then you might try setting it to an empty view:

someObjectWithFirstResponder.inputAccessoryView = [UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];

EDIT This method does not work in iOS 8.0 and greater.

Aron C
  • 838
  • 1
  • 10
  • 17
  • You are correct. I've attempted it in Obj-C and Swift, and neither appear to remove it. I've updated my initial response to indicate that the method does not work in iOS 8. I'll be sure to update my response should I find an applicable solution. – Aron C Jun 09 '14 at 20:13
  • @AronCrittendon I found the solution for iOS 8. You can check it here:http://cocoainios.blogspot.in/2014/11/ios8-uiwebview-remove-or-modify.html – Saurav Nagpal Nov 11 '14 at 05:41
0

There is a solution for this here.

That answer includes a function called removeKeyboardTopBar which should be called on the UIKeyboardWillShowNotification.

  1. Listen to the notification:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    
  2. On the notification, call the function after a delay. The delay is necessary to make sure that the objects exist before the function runs (since we are calling this on keyboard will show, not keyboard did show).

    - (void)keyboardWillShow:(NSNotification*) notification {
        [self performSelector:@selector(removeKeyboardTopBar) withObject:nil afterDelay:0];
    }
    
Community
  • 1
  • 1
Sarah Elan
  • 2,465
  • 1
  • 23
  • 45