Created
July 10, 2015 10:26
-
-
Save sciolist/9fc4c65eeea3e3dc4d39 to your computer and use it in GitHub Desktop.
WKWebView+HideInputAccessoryView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <WebKit/WebKit.h> | |
@interface WKWebView (HideInputAccessoryView) | |
- (void) setAccessoryViewEnabled:(BOOL)on; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <objc/runtime.h> | |
#import "WKWebView+HideInputAccessoryView.h" | |
// http://stackoverflow.com/questions/19033292/ios-7-uiwebview-keyboard-issue/19042279#19042279 | |
@implementation WKWebView (HideInputAccessoryView) | |
- (id)returnsNil { | |
return nil; | |
} | |
- (void) setAccessoryViewEnabled:(BOOL)on { | |
UIView* subview; | |
for (UIView* view in self.scrollView.subviews) { | |
if([[view.class description] hasPrefix:@"WKContentView"]) { | |
subview = view; | |
break; | |
} | |
} | |
if(subview == nil) return; | |
if (on) | |
{ | |
object_setClass(subview, objc_getClass("WKContentView")); | |
} | |
else | |
{ | |
NSString* name = [NSString stringWithFormat:@"%@WKContentView_HideAccessoryView", subview.class.superclass]; | |
Class newClass = NSClassFromString(name); | |
if(newClass == nil) | |
{ | |
newClass = objc_allocateClassPair(subview.class, [name cStringUsingEncoding:NSASCIIStringEncoding], 0); | |
if(!newClass) return; | |
Method method = class_getInstanceMethod([self class], @selector(returnsNil)); | |
class_addMethod(newClass, @selector(inputAccessoryView), method_getImplementation(method), method_getTypeEncoding(method)); | |
objc_registerClassPair(newClass); | |
} | |
object_setClass(subview, newClass); | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment