uiwebview在uiscrollview提示 [英] Uiwebview in uiscrollview tips

查看:117
本文介绍了uiwebview在uiscrollview提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIScrollview 允许分页,和一个 UIWebview 在里面的详细视图。我知道你不应该这样做根据苹果类参考,但我没有看到另一个选项。

I have a UIScrollview to allow for pagination, and a UIWebview on the detail views inside. I know you are not supposed to do that according to Apples Class Reference, but I don't see another option.

为了使反应和体验更好,我停用了 UIWebview 的滚动功能:

In order to make responses and experience a bit better, I disabled scrolling of the UIWebview, with:

[[[webView subviews] lastObject] setScrollEnabled:FALSE];

但现在我正在寻找一个解决方案,使webview的大小取决于内容。有一个简单的方法来做到这一点,其中的webview的宽度保持不变,但高度增长(自动),当需要显示整篇文章?这将删除滚动问题,因为它坐在他的scrollview谁将照顾所有的滚动在这种情况下。

But now I am looking for a solution to make the webview the right size, depending on the content. Is there an easy way to do this, where the width of the webview stays the same, but the height grows (automatically) when that is required to show the full article? This will remove the scrolling problem, as it sit he scrollview who will take care of all the scrolling in this scenario.

这是有意义吗?

推荐答案

从UIWebView的文档中可以看出:

From the documentation for UIWebView, it states:


重要:您不应该在
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.

一个更合适的方法是将UIWebView添加到UIViewController,并在其下面有一个UIScrollView(或UITableView)。我会意识到你将留下的空间,虽然对于滚动视图,特别是如果你在处理的iPhone。

A more appropriate approach would be to add your UIWebView to a UIViewController with a UIScrollView (or UITableView) underneath. I'd be conscious of the amount of space you'll have left though for the scroll view though, especially if you're dealing with the iPhone.

希望这是一个微调正确的方向。

Hope that's a nudge in the right direction.

更新:

我确信会有一种方法),似乎我设法想出的最好的方法是将您的UIWebView添加到UITableView的标题视图。

After looking into this (I was sure there would be a way), it seems the best approach I managed to come up with is to add your UIWebView to the header view of a UITableView.

    //create webview
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 280.0)];

    //load request and scale content to fit
    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.stackoverflow.com/"]]];
    [_webView setScalesPageToFit:YES];

    //add web view to table header view
    [[self tableView] setTableHeaderView:_webview];

这会在表格视图的标题中添加UIWebView,然后才会显示单元格。请注意,表头视图(和页脚视图)也不同于段头(和页脚),所以如果你使用UITableViewStylePlain,你仍然可以使用这两个。

This adds a UIWebView to the header of the table view before the cells are displayed underneath. Note that a table header view (and footer views also) are different from section headers (and footers) so you can still use these two if you are using UITableViewStylePlain.

Be确保减弱webview的框架,以允许下面的任何单元格可见,否则用户将无法滚动tableview,因为任何触摸都将被webview拦截。

Be sure to attenuate the frame of the webview to allow for any cells underneath to be visible or else the user will not be able to scroll the tableview as any touches will be intercepted by the webview.

这仍然违反了UIWebView文档(如上所述),但实际上,只要webview不覆盖视图的整个可滚动区域,这个实现就可以正常工作。

This still goes against the UIWebView documentation (stated above) but, in practice, this implementation actually works fine as long as the webview does not cover the entire scrollable region of the view.

这是我做的测试应用的屏幕截图:

Here's a screenshot of the test app I made:

希望有助于:)

这篇关于uiwebview在uiscrollview提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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