Skip to content

Instantly share code, notes, and snippets.

@alloy
Created July 27, 2011 16:50
Show Gist options
  • Select an option

  • Save alloy/1109803 to your computer and use it in GitHub Desktop.

Select an option

Save alloy/1109803 to your computer and use it in GitHub Desktop.
Disable zooming in a UIWebView _without_ setting scalesPageToFit to NO.
- (void)hijackWebViewScrollViewDelegate:(UIWebView *)webView {
UIScrollView *scrollView = (UIScrollView *)[webView.subviews objectAtIndex:0];
scrollView.delegate = self;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return nil;
}
// The rest of the UIScrollViewDelegate methods are not interesting for us, so forward them to the webview.
#import <objc/runtime.h>
- (BOOL)respondsToSelector:(SEL)sel
{
if ([super respondsToSelector:sel]) {
return YES;
} else {
struct objc_method_description desc = protocol_getMethodDescription(@protocol(UIScrollViewDelegate), sel, NO, YES);
if (desc.name != NULL) {
return [[UIWebView class] instancesRespondToSelector:sel];
}
}
return NO;
}
- (void)forwardInvocation:(NSInvocation *)invocation
{
SEL sel = invocation.selector;
struct objc_method_description desc = protocol_getMethodDescription(@protocol(UIScrollViewDelegate), sel, NO, YES);
if (desc.name != NULL) {
UIScrollView *scrollView = nil;
[invocation getArgument:&scrollView atIndex:2];
UIView *webView = scrollView.superview;
if ([webView respondsToSelector:sel]) {
[invocation invokeWithTarget:webView];
return;
}
}
[super forwardInvocation:invocation];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment