删除UIWebView键盘上的附件项

当UIWebView显示键盘时,顶部有一个小工具栏(附件项),按钮“完成,上一个,下一个”

目前,我使用以下作为解决方法来删除此工具栏:

https://gist.github.com/2048571

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

首先,听一下键盘事件:

[[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:@"= 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:@" 

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