2012-04-02 67 views
0

当UIWebView中显示的键盘上的accesory项目,则在顶部(附件项目)一个小工具栏,有按钮“完成后,上一页,下一页”删除UIWebView的键盘

目前,我使用以下作为一种变通方法来删除此工具栏:

https://gist.github.com/2048571

不过,我担心这可能不是在iOS的未来版本。有没有更好的方法来做到这一点?

+0

Did你找到一个解决方案? – jAckOdE 2012-05-02 03:24:21

+0

不幸的是,我仍然在使用这种方法。 – marklar 2012-05-03 22:39:00

+0

我尝试在这里发布的方法,但它不适用于ios 4.3。我发现这一个:http://stackoverflow.com/questions/8470984/how-to-remove-prev-next-button-from-virtual-keyboard-ios/8682238#comment13460308_8682238它适用于iOS 4.3和更高版本。 – jAckOdE 2012-05-04 04:33:13

回答

1

首先,听键盘事件:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; 

时,键盘会显示,删除工具栏:

- (void)keyboardWillShow:(NSNotification *)note { 
[self performSelector:@selector(removeBar) withObject:nil afterDelay:0]; 
} 

的removeBar如下:

- (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:@"<UIPeripheralHostView"]) { 
      for (UIView* peripheralView in [possibleFormView subviews]) { 

       // hides the backdrop (iOS 7) 
       if ([[peripheralView description] hasPrefix:@"<UIKBInputBackdropView"]) { 
        //skip the keyboard background....hide only the toolbar background 
        if ([peripheralView frame].origin.y == 0){ 
         [[peripheralView layer] setOpacity:0.0]; 
        } 
       } 
       // hides the accessory bar 
       if ([[peripheralView description] hasPrefix:@"<UIWebFormAccessory"]) { 
        // remove the extra scroll space for the form accessory bar 
        UIScrollView *webScroll; 
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) { 
         webScroll = [[self webView] scrollView]; 
        } else { 
         webScroll = [[[self webView] 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:@"<UIImageView"]) { 
        [[peripheralView layer] setOpacity:0.0]; 
       } 
      } 
     } 
    } 
} 

参考:https://github.com/don/KeyboardToolbarRemover/blob/master/src/ios/KeyboardToolbarRemover.m