UIWebView Keyboard - Getting rid of the “Previous/Next/Done” bar

后端 未结 9 2136
清酒与你
清酒与你 2020-12-13 07:05

I want to get rid of the bar on top of the keyboard that appears when you focus a text field in a webview. We have some other ways of handling this and it\'s redundant and

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 08:12

    this code definetly works for me... hope this also works for you.

    - (void)viewDidLoad{
        [super viewDidLoad];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    }
    
    
    -(void)viewWillAppear:(BOOL)animated{
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    }
    
    - (void)keyboardWillShow:(NSNotification *)notification {
        [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 *possibleFormView in [keyboardWindow subviews]) {
            if ([[possibleFormView description] hasPrefix:@"= 5.0) {
                            webScroll = [[self webviewpot] scrollView];
                        } else {
                            webScroll = [[[self webviewpot] subviews] lastObject];
                        }
                        CGRect newFrame = webScroll.frame;
                        newFrame.size.height += peripheralView.frame.size.height;
                        webScroll.frame = newFrame;
    
                        // remove the form accessory bar
                        [peripheralView removeFromSuperview];
                    }
                    // hides the thin grey line used to adorn the bar (iOS 6)
                    if ([[peripheralView description] hasPrefix:@"

提交回复
热议问题