在从博客加载网络内容的小型应用程序中,如果 UIWebView(位于 UIScrollView 内可滚动)不会将所有内容滚动到 View 中,如果它比实际 UIScrollView 的框架长。这是问题的图片:
加载 UIScrollView 和 UIWebView 的代码(这是 UIViewController 的一部分)
- (id)initWithHTML:(NSString*)html
{
self = [super init];
if (self) {
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
UIScrollView* v = [[UIScrollView alloc] initWithFrame:appFrame];
self.view = v;
UIWebView* webView = [[UIWebView alloc] initWithFrame:v.frame];
webView.userInteractionEnabled = NO;
webView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:webView];
[webView loadHTMLString:html baseURL:nil];
CGSize sz = v.bounds.size;
sz.height = webView.bounds.size.height + 20;
v.contentSize = sz;
[v release];
[webView release];
}
return self;
}
最佳答案
来自 Apple 的文档:
重要提示:您不应在 UIScrollView 对象中嵌入 UIWebView 或 UITableView 对象。如果这样做,可能会导致意外行为,因为两个对象的触摸事件可能会混淆并错误处理。
可能是当您滚动时,事件变得困惑。这可能是它阻止您将其余内容滚动到 View 中的原因。
关于iphone - UIScrollView 内的 UIWebView 框架不会拉伸(stretch)大小以适应所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7393201/