Remove UIWebView Shadow?

后端 未结 15 1195
慢半拍i
慢半拍i 2020-12-02 11:12

Does anyone know if its possible to remove the shadow that is placed on the UIWebView window?

Example: http://uploadingit.com/files/1173105_olub5/shadow.png

15条回答
  •  天命终不由人
    2020-12-02 12:02

    There is a private method with the selector setAllowsRubberBanding: that takes a BOOL value. If passed NO, you will not be able to scroll the web view past the top or bottom of the content area, but will still let you scroll through the web view normally. Unfortunately, this method IS private, and your app will likely not be allowed onto the store if you use it.

    You could, however, potentially try and extract the method implementation and bind it to a different selector that you've created, using the dynamic nature of Objective-C's runtime.

    Still, the method is private and may no longer exist in future versions of the OS. If you still want to try, here's some sample code that will extract the setAllowsRubberBanding: method implementation and call it for you.

    static inline void ShhhDoNotTellAppleAboutThis (UIWebView *webview)
    {
        const char *hax3d = "frgNyybjfEhooreOnaqvat";
        char appleSelName[24];
    
        for (int i = 0; i < 22; ++i)
        {
            char c = hax3d[i];
            appleSelName[i] = (c >= 'a' && c <= 'z') ? ((c - 'a' + 13) % 26) + 'a' : ((c - 'A' + 13) % 26) + 'A';
        }
        appleSelName[22] = ':';
        appleSelName[23] = 0;
    
        SEL appleSEL = sel_getUid(appleSelName);
    
        UIScrollView *scrollView = (UIScrollView *)[webview.subviews objectAtIndex:0];
        Class cls = [scrollView class];
        if (class_respondsToSelector(cls, appleSEL) == NO)
        {
            return;
        }
    
        IMP func = class_getMethodImplementation(cls, appleSEL);
        func(scrollView, appleSEL, NO);
    }
    

    Please note that this will probably still get caught by Apple's static analyzer if you choose to submit an app using this code to the AppStore.

提交回复
热议问题