在當(dāng)前類的最前面加上
//隱藏webview調(diào)用鍵盤之后 的 功能鍵:比如完成
@interfaceUIWebView (HackishAccessoryHiding)
@property(nonatomic,assign)BOOLhidesInputAccessoryView;
@end
@implementationUIWebView (HackishAccessoryHiding)
static const char * const hackishFixClassName = "UIWebBrowserViewMinusAccessoryView";
staticClasshackishFixClass =Nil;
- (UIView*)hackishlyFoundBrowserView {
? ? UIScrollView *scrollView = self.scrollView;
? ? UIView*browserView =nil;
? ? for(UIView*subviewinscrollView.subviews) {
? ? ? ? if ([NSStringFromClass([subview class]) hasPrefix:@"UIWebBrowserView"]) {
? ? ? ? ? ? browserView = subview;
? ? ? ? ? ? break;
? ? ? ? }
? ? }
? ? returnbrowserView;
}
- (id)methodReturningNil {
? ? return nil;
}
- (void)ensureHackishSubclassExistsOfBrowserViewClass:(Class)browserViewClass {
? ? if (!hackishFixClass) {
? ? ? ? ClassnewClass =objc_allocateClassPair(browserViewClass,hackishFixClassName,0);
? ? ? ? newClass =objc_allocateClassPair(browserViewClass,hackishFixClassName,0);
? ? ? ? IMPnilImp = [selfmethodForSelector:@selector(methodReturningNil)];
? ? ? ? class_addMethod(newClass,@selector(inputAccessoryView), nilImp,"@@:");
? ? ? ? objc_registerClassPair(newClass);
? ? ? ? hackishFixClass= newClass;
? ? }
}
- (BOOL) hidesInputAccessoryView {
? ? UIView *browserView = [self hackishlyFoundBrowserView];
? ? return[browserViewclass] ==hackishFixClass;
}
- (void) setHidesInputAccessoryView:(BOOL)value {
? ? UIView *browserView = [self hackishlyFoundBrowserView];
? ? if(browserView ==nil) {
? ? ? ? return;
? ? }
? ? [self ensureHackishSubclassExistsOfBrowserViewClass:[browserView class]];
? ? if(value) {
? ? ? ? object_setClass(browserView,hackishFixClass);
? ? }
? ? else{
? ? ? ? ClassnormalClass =objc_getClass("UIWebBrowserView");
? ? ? ? object_setClass(browserView, normalClass);
? ? }
? ? [browserViewreloadInputViews];
}
@end
之后:
_webView.hidesInputAccessoryView = YES;//隱藏鍵盤上方功能鍵