¿Cómo evitar ocultar el keyboard y mostrar cuando cambia el enfoque de UITextField y UIWebView?

Tengo un requisito en el que la vista contiene un UITextField nativo y un UIWebView. El problema es que si cambio el foco de UITextView a UIWebView, el parpadeo de la window del keyboard (oculta y luego se muestra). es decir, obtuve UIKeyboardWillHideNotification y UIKeyboardDidShowNotification

Pero, esto no ocurre cuando cambio de sentido. Tengo solo UIKeyboardDidShowNotification

¿Hay alguna manera de evitar este efecto de parpadeo?

Nota: También me aviso si tengo varios UITextField y UIWebView, este problema no ocurre con el mismo tipo de vistas.

He resuelto este problema a través del código a continuación. Simplemente configure webView.usesGUIFixes = YES; y debería resolver tu problema. El código a continuación también le permite configurar una vista de input personalizada para usar para el keyboard UIWebView:

UIWebView + GUIFixes.h

 #import <UIKit/UIKit.h> @interface UIWebView (GUIFixes) /** * @brief The custom input accessory view. */ @property (nonatomic, strong, readwrite) UIView* customInputAccessoryView; /** * @brief Wether the UIWebView will use the fixes provided by this category or not. */ @property (nonatomic, assign, readwrite) BOOL usesGUIFixes; @end 

UIWebView + GUIFixes.m

 #import "UIWebView+GUIFixes.h" #import <objc/runtime.h> @implementation UIWebView (GUIFixes) static const char* const kCustomInputAccessoryView = "kCustomInputAccessoryView"; static const char* const fixedClassName = "UIWebBrowserViewMinusAccessoryView"; static Class fixClass = Nil; - (UIView *)browserView { UIScrollView *scrollView = self.scrollView; UIView *browserView = nil; for (UIView *subview in scrollView.subviews) { if ([NSStringFromClass([subview class]) hasPrefix:@"UIWebBrowserView"]) { browserView = subview; break; } } return browserView; } - (id)methodReturningCustomInputAccessoryView { UIView* view = [self performSelector:@selector(originalInputAccessoryView) withObject:nil]; if (view) { UIView* parentWebView = self.superview; while (parentWebView && ![parentWebView isKindOfClass:[UIWebView class]]) { parentWebView = parentWebView.superview; } UIView* customInputAccessoryView = [(UIWebView*)parentWebView customInputAccessoryView]; if (customInputAccessoryView) { view = customInputAccessoryView; } } return view; } - (BOOL)delayedBecomeFirstResponder { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [super becomeFirstResponder]; }); return YES; } - (void)ensureFixedSubclassExistsOfBrowserViewClass:(Class)browserViewClass { if (!fixClass) { Class newClass = objc_allocateClassPair(browserViewClass, fixedClassName, 0); IMP oldImp = class_getMethodImplementation(browserViewClass, @selector(inputAccessoryView)); class_addMethod(newClass, @selector(originalInputAccessoryView), oldImp, "@@:"); IMP newImp = [self methodForSelector:@selector(methodReturningCustomInputAccessoryView)]; class_addMethod(newClass, @selector(inputAccessoryView), newImp, "@@:"); objc_registerClassPair(newClass); IMP delayedFirstResponderImp = [self methodForSelector:@selector(delayedBecomeFirstResponder)]; Method becomeFirstResponderMethod = class_getInstanceMethod(browserViewClass, @selector(becomeFirstResponder)); method_setImplementation(becomeFirstResponderMethod, delayedFirstResponderImp); fixClass = newClass; } } - (BOOL)usesGUIFixes { UIView *browserView = [self browserView]; return [browserView class] == fixClass; } - (void)setUsesGUIFixes:(BOOL)value { UIView *browserView = [self browserView]; if (browserView == nil) { return; } [self ensureFixedSubclassExistsOfBrowserViewClass:[browserView class]]; if (value) { object_setClass(browserView, fixClass); } else { Class normalClass = objc_getClass("UIWebBrowserView"); object_setClass(browserView, normalClass); } [browserView reloadInputViews]; } - (UIView*)customInputAccessoryView { return objc_getAssociatedObject(self, kCustomInputAccessoryView); } - (void)setCustomInputAccessoryView:(UIView*)view { objc_setAssociatedObject(self, kCustomInputAccessoryView, view, OBJC_ASSOCIATION_RETAIN); } @end