美文网首页专注iOS开发的小渣渣
在webview上IQKeyboardManager的禁用too

在webview上IQKeyboardManager的禁用too

作者: 蜗蜗牛在奔跑 | 来源:发表于2019-12-18 11:49 被阅读0次
    • (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:@"<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; }

    Blockquote

    相关文章

      网友评论

        本文标题:在webview上IQKeyboardManager的禁用too

        本文链接:https://www.haomeiwen.com/subject/ylaynctx.html