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?
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]; } } You can also access scrollView as follows:
webView.scrollView.scrollEnabled = false; webView.scrollView.bounces = false; 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]; No need to use sophisticated methods. You can access the scroll webview directly, as shown below.
web_view.scrollView.scrollEnabled = NO;