touchMo...">

Disable the default scroll behavior of UIWebView using objective-c

I know you can use javascript for this

<script type="text/javascript"> touchMove = function(event) { event.preventDefault(); } 

Is there a way to do the same with objective-c?

+6
objective-c iphone uiwebview
source share
4 answers

try it...

 UIView * v = [[webView subviews] lastObject]; [v setScrollEnabled:NO]; [v bounces:NO]; 

EDIT: Added checks for the original answer based on the comment below

 UIView * v = [[webView subviews] lastObject]; if([v isKindOfClass:[UIScrollView class] ]) { if ([v respondsToSelector:@selector(setScrollEnabled]) { [v setScrollEnabled:NO]; } if ([v respondsToSelector:@selector(bounces)]) { [v bounces:NO]; } } 
+7
source share

You can also access scrollView as follows:

 webView.scrollView.scrollEnabled = false; webView.scrollView.bounces = false; 
+2
source share

Using @ aaron-saunders and @ matt-rix answers, here is what works best for me:

 UIView *v = [[webView subviews] lastObject]; if([v isKindOfClass:[UIScrollView class]]) [v setScrollEnabled:NO]; 
+1
source share

No need to use sophisticated methods. You can access the scroll webview directly, as shown below.

web_view.scrollView.scrollEnabled = NO;

0
source share

All Articles