iOS keyboard style in webview?

后端 未结 2 1530
小鲜肉
小鲜肉 2021-01-16 23:23

I am pretty new to web development, my project is using Jquery-mobile, Phonegap and compass (scss).

By default, the keyboard showing up when an input field gets focu

相关标签:
2条回答
  • 2021-01-17 00:08

    To remove the bar you should dive into the objective-c code.

    This is the code that I use: (inside the controller that contains your UIWebview add the following code)

    First add an observer to receive the notification for the keyboard :

    -(void)viewWillAppear:(BOOL)animated{
       [[NSNotificationCenter defaultCenter] addObserver:self
                                                selector:@selector(keyboardWillShow:)
                                                    name:UIKeyboardWillShowNotification
                                                  object:nil];
    }
    
    - (void)keyboardWillShow:(NSNotification *)note {
        [self performSelector:@selector(removeBar) withObject:nil afterDelay:0];
    }
    - (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 *formView in [keyboardWindow subviews]) {
        // iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
        if ([[formView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) {
            for (UIView *subView in [formView subviews]) {
                if ([[subView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) {
                    // remove the input accessory view
                    [subView removeFromSuperview];
                }
                else if([[subView description] rangeOfString:@"UIImageView"].location != NSNotFound){
                    // remove the line above the input accessory view (changing the frame)
                    [subView setFrame:CGRectZero];
                }
            }
          }
        }
    }
    
    0 讨论(0)
  • 2021-01-17 00:23

    I was working on iOS 7.0 and fixed it with the following code on UIWebView

    -(void)removeExtraBar
    {
        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]) {
            if ([[possibleFormView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) {
                for (UIView *subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
                    if ([[subviewWhichIsPossibleFormView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) {
                        [subviewWhichIsPossibleFormView removeFromSuperview];
                    }
                    else if([[subviewWhichIsPossibleFormView description] rangeOfString:@"UIKBInputBackdropView"].location != NSNotFound) {
                        [subviewWhichIsPossibleFormView removeFromSuperview];
                    }
                }
            }
        }
    }
    

    This works for me with the UIWebView keyboard issue on iOS 7.0

    0 讨论(0)
提交回复
热议问题