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
Starting with iOS5 we have direct access to the scrollview of the UIWebView.
You can disable scrolling and bounces like this:
webView.scrollView.scrollEnabled = NO;
webView.scrollView.bounces = NO;
I think the Javascript
<script type="text/javascript">
touchMove = function(event) {
event.preventDefault();
}
is far the best solution.
Indeed :
Your first examle, or the
[[[WebView subviews] lastObject] setScrollingEnabled:NO];
one (same things) could be rejected because not documented, or make you app crash in a further ios update.
And the
[[myWebView scrollView] setBounces:NO];
method won't work with iOS < 5.
I don't think the first option is forbidden by Apple.
You could try
[[[Webview subviews] lastObject] setScrollingEnabled:NO];
If you don't want any links to work in your UIWebView, you can also do
[myWebView setUserInteractionEnabled:NO];
SWIFT 3 version
webView.scrollView.bounces = false
webView.scrollView.isScrollEnabled = false
I placed some UIWebView
s inside a UIScrollView
and it wasn't scrolling for me, unless I disable the user interaction on the webviews (even with the [[webview scrollview] setScrollEnabled:NO]
). So I placed the UIWebView
s inside a UIView
and that worked for me but then the interactive links or divs in my HTML inside the UIWebView
were not working anymore.
The only thing that worked for me is to keep the UIWebView
inside the UIScrollView
so the HTML interactions work but the UIScrolling
does not.
I then created a custom delegate for the webviews to listen for window.open("http:/customEvent")
that is called from the HTML contained in the webview. I also added a JavaScript swipe detection that will fire up my custom event.
When the webview delegate receives this, I pass a notification to a controller which then dynamically scrolls my UIScrollView
. Obviously I had to build a logic to monitor and scroll to the next or previous page. Not the prettiest solution but It's working for me.
Use this one <body ontouchmove="event.preventDefault()">