为什么UIWebView不能放在UIScrollView中? [英] Why Shouldn't A UIWebView Be Placed in a UIScrollView?

查看:331
本文介绍了为什么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 docs for UIWebView 上,他们声明:

If you look at the Apple docs for UIWebView, they state:


重要:您不应在
UIScrollView对象中嵌入UIWebView或UITableView对象。如果你这样做,意外的行为可能导致
,因为两个对象的触摸事件可能混淆而且错误地处理

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 可以轻松显示各种网络内容。

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不建议在 UIScrollViews 内放置 UIWebViews 的唯一原因,如果你解释的那个:因为滚动可能会在两个滚动视图之间混淆。

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 ,因此不是一个scrollview本身(但嵌入一个),这个对于未经实验的用户来说,可能不明显的是,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中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆