Disable Scroll on a UIWebView allowed?

2019-01-16 04:36发布

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 tableView header.

In order to do that I have to get the height of the webView content and I have to disable scrolling for the webView.

I found two solutions to disable scrolling:

for (id subview in webView.subviews)
    if ([[subview class] isSubclassOfClass: [UIScrollView class]])
        ((UIScrollView *)subview).scrollEnabled=NO;

or in JavaScript:

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

I heard that the first solution is forbidden by Apple but I don't have any proof of it. Will my application be rejected by using this solution? If so, can I use the second solution without being rejected?

18条回答
Viruses.
2楼-- · 2019-01-16 05:17

Use it :

[[webView scrollView] setBounces:NO];
[[webView scrollView] setScrollingEnabled:NO];
查看更多
萌系小妹纸
3楼-- · 2019-01-16 05:18

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 :)

查看更多
爷、活的狠高调
4楼-- · 2019-01-16 05:18

You can simply set the web view user interaction property to no i.e.

webView.userInteractionEnabled = NO;

Its pretty simple and works fine,thanks :)

查看更多
冷血范
5楼-- · 2019-01-16 05:19

Is a UIWebview and a UITableView on a UIScrollview, and setting the height of the webview (and adding to the total ContentSize of the Scrollview) like what you want?

查看更多
beautiful°
6楼-- · 2019-01-16 05:21

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;
    }
}
查看更多
萌系小妹纸
7楼-- · 2019-01-16 05:23

SWIFT 3 version

    webView.scrollView.bounces = false
    webView.scrollView.isScrollEnabled = false
查看更多
登录 后发表回答