Why Shouldn't A UIWebView Be Placed in a UIScrollView?

感情迁移 提交于 2019-11-30 00:44:34

The only reason Apple does not recommend putting UIWebViews inside UIScrollViews if for the one you explain: because scrolling would risk to be mixed up between the two scroll views.

I guess they wrote this because, by the fact that UIWebView inherits UIView and not UIScrollView, and thus is not a scrollview itself (but embeds one), this may be not obvious for the unexperimented user that the web content can be scrollable depending on the HTML, which would mess up with the container scrollview if any. So that is probably just a reminder for this case.

But if you disable the scrolling, I can't see any reason why this would go wrong.

Note anyway that disabling user interaction on the scrollview is not the same as disabling scrolling. If your HTML content contains links or other clickable/tappable content, disabling user interaction will disable them too. To only disable scrolling only but keep user interaction like simple taps, use webview.scrollView.scrollEnabled = NO instead of webview.scrollView.userInteractionEnabled = NO.

I have encountered at least one other reason for this:

UIWebViews appear not to run any JavaScript while they are scrolling. My JavaScript-animated content is frozen while the web view is scrolling and continues where it left off as soon as scrolling ends.

Presumably, this is a performance optimization. Now when we scroll a scroll view that contains web views, the web views are not aware that they are moving, and thus will not pause their JavaScript.

The question, of course, is whether or not this affects performance in a significant way, and on which iPad models.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!