在webview上IQKeyboardManager的禁用toolbar不好使

  • (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) 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:@" {
    for(int i = 0 ; i < [possibleFormView.subviews count] ; i++)
    {
    UIView
    hostkeyboard = [possibleFormView.subviews objectAtIndex:i];
    if([[hostkeyboard description] hasPrefix:@" {
    for (id temp in hostkeyboard.subviews)
    {
    if ([[temp description] hasPrefix:@" {
    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; }

Blockquote

你可能感兴趣的:(在webview上IQKeyboardManager的禁用toolbar不好使)