Phonegap iOS6: Proper solution to Remove form assistant bar (prev, next, done)

前端 未结 6 1003
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 06:07

Another \"how to remove the pre, next, done button\" -question you may think. Not really actually. I\'ve done some rather thorough research on this and tried out di

6条回答
  •  北海茫月
    2020-12-31 06:49

    Here you go, I'm using this in an app I'm currently developing. Fingers crossed that it gets to the app store, although going on other 'hacks' that make it to the store this is no worse than others, so should stand a fair chance.

    No annoying side effects with this method - it cleanly removes the bar by making sure it's never created in the first place. Ta da!

    Credit goes to https://gist.github.com/2048571, this is his code with a small fix.

    #import 
    #import 
    
    @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
    

提交回复
热议问题