How to disable UIWebView from user scrolling?

#import <objc/runtime.h>

    id scroller = [[Webview subviews] lastObject];
    int count;
    Method *method = class_copyMethodList([scroller class], &count);
    int i;
    for (i=0; i<count; i++) {
        if (strcmp(method_getName(method[i]), "setScrollingEnabled:") == 0)
            break;
    }
    IMP test = method_getImplementation(method[i]);
    test(scroller, @selector(setScrollingEnabled:), NO);

Blogged with the Flock Browser

6 Responses to “How to disable UIWebView from user scrolling?”

  1. wow! Says:

    incredible!

  2. slaing Says:

    Don’t forget to free(method) or you’ll have a leak on your hands.

  3. uh Says:

    or you could just do :
    [[[WebView subviews] lastObject] setScrollingEnabled:NO];

    this is objective-c, you know :)

  4. Hussain Says:

    not working for 3.0 i guess. it just gives me no such method found.

    There is another method called setScrollEnabled but thats giving error

  5. Georg Says:

    id scrollView = [[self subviews] lastObject];
    if([scrollView respondsToSelector:@selector(setScrollingEnabled:)]) [scrollView performSelector:@selector(setScrollingEnabled:) withObject:NO];


Leave a Reply