Why Shouldn#39;t A UIWebView Be Placed in a UIScrollView?(为什么 UIWebView 不应该放在 UIScrollView 中?)
问题描述
有谁知道在 iOS 上避免滚动视图中的网页视图的技术原因(假设您愿意自己禁用网页视图中的滚动)?
Does anyone know of technical reasons for avoiding web views inside scroll views on iOS (assuming you're willing to disable scrolling inside the web views themselves)?
如果您查看 Apple 文档对于 UIWebView,他们声明:
If you look at the Apple docs for UIWebView, they state:
重要提示:您不应将 UIWebView 或 UITableView 对象嵌入UIScrollView 对象.如果这样做,可能会导致意外行为因为两个对象的触摸事件可能会混淆和错误处理.
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
我的猜测
看起来他们可能是在警告您不要将滚动视图放在另一个滚动视图中,因为内部滚动视图和外部滚动视图之间的触摸可能会混淆.
My Educated Guess
It looks like maybe they're warning you against putting a scroll view inside another scroll view, because touches can be confused between the inner, and outer scroll views.
但是,将 UIWebView
放在滚动视图中是有充分理由的.Web 视图不仅仅是 滚动视图.UIWebView
可以轻松显示范围广泛的web 内容.
But, there's a very valid reason to want to put a UIWebView
inside a scroll view. Web views aren't just scroll views. UIWebView
can easily display a wide range of web content.
如果不需要允许 在 UIWebView
本身内滚动,并且您使用以下任一方法关闭滚动:
If there is no need to allow scrolling within the UIWebView
itself, and you turn off scrolling with either:
webView.userInteractionEnabled = NO;
或
webView.scrollView.scrollEnabled = NO;
那么这个设计真的有问题吗?
then is there really any problem with this design?
我想知道这是否部分是原始 UIWebView
界面的工件,它没有为您提供 直接(并记录)访问其嵌入的 UIScrollView
(能够轻松禁用其滚动).也许 Apple 文档中的这句话是遗留下来的?
I'm wondering if this is partly an artifact of the original UIWebView
interface, where it did not give you direct (and documented) access to its embedded UIScrollView
(to be able to disable its scrolling easily). Maybe this statement in the Apple docs is a legacy of that?
我问是因为我正在维护一个应用程序(由其他人编写),该应用程序在允许水平滚动的滚动视图中使用少数 Web 视图.Web 内容必须被认为是固定的(不可更改),并且每个 HTML 页面只显示一页内容.用户需要能够在页面之间滚动,因此为此选择了 UIScrollView
内的多个 UIWebViews
.到目前为止,它似乎可能工作正常.
I ask because I'm maintaining an app (written by someone else) that uses a handful of web views inside a scroll view that allows scrolling between them horizontally. The web content must be considered fixed (not changeable), and it only shows one page of content per HTML page. The user needs to be able to scroll between pages, so multiple UIWebViews
inside a UIScrollView
were chosen for that. So far, it appears that it may be working properly.
但是,页面显示全屏图像,并且滚动性能是一个问题.但是,我正在尝试确定滚动视图中 Web 视图的基本嵌套(Apple 警告不要这样做)是否真的是问题的一部分.
However, the pages show full screen images, and scrolling performance is an issue. But, I'm trying to determine if the fundamental nesting of web views inside scroll views (which Apple warns against) is really part of the problem.
推荐答案
Apple 不建议将 UIWebViews
放在 UIScrollViews
中的唯一原因,如果你解释的原因:因为滚动可能会在两个滚动视图之间混淆.
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.
我猜他们写这个是因为 UIWebView
继承 UIView
而不是 UIScrollView
,因此它本身不是滚动视图(但嵌入一个),这对于没有经验的用户来说可能并不明显,Web 内容可以根据 HTML 滚动,如果有的话,这会弄乱容器滚动视图.所以这可能只是对这个案例的提醒.
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.
请注意,在滚动视图上禁用用户交互与禁用滚动不同.如果您的 HTML 内容包含链接或其他可点击/可点击的内容,禁用用户交互也会禁用它们.要仅禁用滚动但保持用户交互(如简单的点击),请使用 webview.scrollView.scrollEnabled = NO
而不是 webview.scrollView.userInteractionEnabled = NO
.
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
.
这篇关于为什么 UIWebView 不应该放在 UIScrollView 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 UIWebView 不应该放在 UIScrollView 中?
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01