Created
July 27, 2011 16:50
-
-
Save alloy/1109803 to your computer and use it in GitHub Desktop.
Disable zooming in a UIWebView _without_ setting scalesPageToFit to NO.
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
| - (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