Created
March 16, 2012 05:03
-
-
Save bjhomer/2048571 to your computer and use it in GitHub Desktop.
Hiding the inputAccessoryView of a UIWebView
This file contains hidden or 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 <UIKit/UIKit.h> | |
@interface UIWebView (HackishAccessoryHiding) | |
@property (nonatomic, assign) BOOL hackishlyHidesInputAccessoryView; | |
@end | |
@implementation UIWebView (HackishAccessoryHiding) | |
static const char * const hackishFixClassName = "UIWebBrowserViewMinusAccessoryView"; | |
static Class hackishFixClass = Nil; | |
- (UIView *)hackishlyFoundBrowserView { | |
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)methodReturningNil { | |
return nil; | |
} | |
- (void)ensureHackishSubclassExistsOfBrowserViewClass:(Class)browserViewClass { | |
if (!hackishFixClass) { | |
newClass = objc_allocateClassPair(browserViewClass, hackishFixClassName, 0); | |
IMP nilImp = [self methodForSelector:@selector(methodReturningNil)]; | |
class_addMethod(newClass, @selector(inputAccessoryView), nilImp, "@@:"); | |
objc_registerClassPair(newClass); | |
hackishFixClass = newClass; | |
} | |
} | |
- (BOOL) hackishlyHidesInputAccessoryView { | |
UIView *browserView = [self hackishlyFoundBrowserView]; | |
return [browserView class] == hackishFixClass; | |
} | |
- (void) setHackishlyHidesInputAccessoryView:(BOOL)value { | |
UIView *browserView = [self hackishlyFoundBrowserView]; | |
if (browserView == nil) { | |
return; | |
} | |
[self ensureHackishSubclassExistsOfBrowserViewClass:[browserView class]]; | |
if (value) { | |
object_setClass(browserView, hackishFixClass); | |
} | |
else { | |
Class normalClass = objc_getClass("UIWebBrowserView"); | |
object_setClass(browserView, normalClass); | |
} | |
[browserView reloadInputViews]; | |
} | |
@end |
This file contains hidden or 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 <UIKit/UIKit.h> | |
@interface UIWebView (HackishAccessoryHiding) | |
@property (nonatomic, assign) BOOL hackishlyHidesInputAccessoryView; | |
@end | |
@implementation UIWebView (HackishAccessoryHiding) | |
static const char * const hackishFixClassName = "UIWebBrowserViewMinusAccessoryView"; | |
static Class hackishFixClass = Nil; | |
- (UIView *)hackishlyFoundBrowserView { | |
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)methodReturningNil { | |
return nil; | |
} | |
- (void)ensureHackishSubclassExistsOfBrowserViewClass:(Class)browserViewClass { | |
if (!hackishFixClass) { | |
Class newClass = objc_allocateClassPair(browserViewClass, hackishFixClassName, 0); | |
IMP nilImp = [self methodForSelector:@selector(methodReturningNil)]; | |
class_addMethod(newClass, @selector(inputAccessoryView), nilImp, "@@:"); | |
objc_registerClassPair(newClass); | |
hackishFixClass = newClass; | |
} | |
} | |
- (BOOL) hackishlyHidesInputAccessoryView { | |
UIView *browserView = [self hackishlyFoundBrowserView]; | |
return [browserView class] == hackishFixClass; | |
} | |
- (void) setHackishlyHidesInputAccessoryView:(BOOL)value { | |
UIView *browserView = [self hackishlyFoundBrowserView]; | |
if (browserView == nil) { | |
return; | |
} | |
[self ensureHackishSubclassExistsOfBrowserViewClass:[browserView class]]; | |
if (value) { | |
object_setClass(browserView, hackishFixClass); | |
} | |
else { | |
Class normalClass = objc_getClass("UIWebBrowserView"); | |
object_setClass(browserView, normalClass); | |
} | |
[browserView reloadInputViews]; | |
} | |
@end |
how do i do this for wkwebview
@tinhbka
replace UIWebView's inputView :
-(id)methodReturningKeyboard {
return [[JSInputView alloc] initWithFrame:CGRectZero];
}
- (void)ensureHackishSubclassExistsOfBrowserViewClass:(Class)browserViewClass {
if (!hackishFixClass) {
Class newClass = objc_allocateClassPair(browserViewClass, hackishFixClassName, 0);
newClass = objc_allocateClassPair(browserViewClass, hackishFixClassName, 0);
IMP keyboardImp = [self methodForSelector:@selector(methodReturningKeyboard)];
class_addMethod(newClass, @selector(inputView), keyboardImp, "@@:");
objc_registerClassPair(newClass);
hackishFixClass = newClass;
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I also posted a gist that allows to customize OR disable the inputAccessoryView:
https://gist.github.com/kgaidis/5f9a8c7063b687cc3946fad6379c1a66