1

I am using IQKeyboardManagerSwift in my app. It is working perfectly in some ViewControllers I have to disable it's toolbar. According to documentation I should add viewcontrollers in which I want to disable toolbar in following array.

IQKeyboardManager.sharedManager().disabledToolbarClasses = []

Now It is working perfectly for TextFields in view controller. But problem is with TextFields inside webview. I have a viewcontroller in which I have to input data in fields inside WebView, for fields inside webview Toolbar is not disabled I tried many ways. Even disabling IQKeyBaord (IQKeyboardManager.sharedManager().enable = false) for whole app doesn't effect WebView

I do not understand what is the issue is there some specific handling for WebView or what can be possible alternate.

For clarification top view with Done button is toolbar that I am referring.

enter image description here

Zia ur Rehman
  • 331
  • 1
  • 2
  • 20
  • 2
    It actually doesn't support WebView since webview has their html textFields, neither UITextField nor UITextView. Refer this https://github.com/hackiftekhar/IQKeyboardManager/issues/1207 – Vinaykrishnan Apr 17 '18 at 09:05
  • I am facing similar issue not for a web view but for a controller which is instantiated from another library. I don't want to edit the library yet and also tried disabling it, still the problem is there. – Moaz Khan Apr 17 '18 at 09:06
  • @Vinaykrishnan Thanks for issue link, yes that's the same issue. And trouble is that it actually shows the toolbar if error was that t doesn't show toolbar then It would have been easy. Now only alternate that I can think of is change library. – Zia ur Rehman Apr 17 '18 at 09:13
  • Seem so, since they haven't provided any solution. – Vinaykrishnan Apr 17 '18 at 09:37

1 Answers1

4

Toolbar over the keyboard is the default property/behaviour of WebView/WKWebView.

But if you want to remove it, here is the code, you can modify it according to your need :

ViewController.h

 #import <UIKit/UIKit.h>
 @interface ViewController : UIViewController
 @property (weak, nonatomic) IBOutlet UIWebView *webView;
 @end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(removeKeyboardTopBar:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(removeKeyboardTopBar:) name:UIKeyboardDidShowNotification object:nil];
}

-(void)viewDidAppear:(BOOL)animated{
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://html5doctor.com/demos/forms/forms-example.html"]];
    [_webView loadRequest:request];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void) removeKeyboardTopBar:(NSNotification*)notify{
    // Locate non-UIWindow.
    UIWindow *keyboardWindow = nil;
    __block UIView* toolBarContainer = nil;
    NSArray* windows = [[UIApplication sharedApplication] windows];
    for (UIWindow *possibleWindow in windows) {
        if (![[possibleWindow class] isEqual:[UIWindow class]]) {
            keyboardWindow = possibleWindow;
            break;
        }
    }
        for (UIView *possibleFormView in [keyboardWindow subviews])
        {
            if([[[UIDevice currentDevice] systemVersion] floatValue]>8){
                if([[possibleFormView description] hasPrefix:@"<UIInputSetContainerView"])
                {
                    for(int i = 0 ; i < [possibleFormView.subviews count] ; i++)
                    {
                        UIView* hostkeyboard = [possibleFormView.subviews objectAtIndex:i];
                        if([[hostkeyboard description] hasPrefix:@"<UIInputSetHostView"])
                        {
                            for (id temp in hostkeyboard.subviews)
                            {
                                if ([[temp description] hasPrefix:@"<UIWebFormAccessory"])
                                {
                                    UIView* currentToolBar = (UIView*)temp;
                                    currentToolBar.hidden = true;
                                    toolBarContainer = hostkeyboard;
                                }
                            }
                        }
                    }
                }
            }else{
                if ([[possibleFormView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) {
                    for (UIView *subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
                        if ([[subviewWhichIsPossibleFormView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) {
                            [subviewWhichIsPossibleFormView removeFromSuperview];
                        }
                    }
                }
            }

        }
    if(toolBarContainer){
        if([notify.name isEqualToString:@"UIKeyboardWillShowNotification"]){
            [toolBarContainer setHidden:YES];
        }else if([notify.name isEqualToString:@"UIKeyboardDidShowNotification"]){
            [toolBarContainer setHidden:NO];
        }
        dispatch_async(dispatch_get_main_queue(), ^(){                
            toolBarContainer.frame = CGRectMake(toolBarContainer.frame.origin.x,toolBarContainer.frame.origin.y+44,toolBarContainer.frame.size.width,toolBarContainer.frame.size.height);
        });
    }

    keyboardWindow = nil;
}
Prabhat Sutar
  • 343
  • 1
  • 11