I have to show a web article with a UITableView
under the article.
The only option I found was to display the article in a UIWebView
in the
Try this in your HTML (<HEAD>
tag)
<script>
document.ontouchmove = function(event) { event.preventDefault(); }
</script>
It will disable scrolling on your web page.
(works on any webpage, not just UIWebView)
I needed to disable scrolling because dismissing a custom keyboard really messed up scrolling with the webView. Nothing else worked and I resorted to something like this:
-(void)viewDidLoad{
[super viewDidLoad];
[self.webView.scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
self.webView.scrollView.showsVerticalScrollIndicator = NO;
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
if (!CGPointEqualToPoint(self.webView.scrollView.contentOffset, CGPointZero)){
self.contentOffset = CGPointZero;
}
}
Since this question is still applicable, there is a new way to do it! (iOS 7.0+, perhaps iOS 6 also, not confirmed)
webView.scrollView.scrollEnabled = NO;
Take care :)
You can simply set the web view user interaction property to no i.e.
webView.userInteractionEnabled = NO;
Its pretty simple and works fine,thanks :)
[[[WebView subviews] lastObject] setScrollingEnabled:NO];
for all ios versions you can use this code instead of setScrollEnabled :
for (UIView *view in webview.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
UIScrollView *scrollView = (UIScrollView *)view;
scrollView.scrollEnabled = NO;
}
}