2009-04-21 41 views
0

我们试图为RSS类应用程序实现文章详细视图。窗口有一个UIScrollView,它包含一个UITextView(它是标题),一个UIButton(它将打开一个图库)和一个UIWebView(与正文一起)。这个想法是,所有这些元素一起滚动...将各种视图插入UIScrollView

问题是,只要我们有超过1000px高的身体,该标记下的所有内容都会被截断。我们已经听说这是因为这是视图的最大高度,并且由于Scroll由顶层的UIScrollView处理,所以没有办法看到进一步下降的情况。

有没有人知道解决这个问题的方法?

谢谢!

----更新1 ----

我们已经打破了体内转化为900px,高块,但第一个毕竟网页视图显示任何内容...

UIScrollView *scroll=[[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
[scroll setBackgroundColor:[UIColor whiteColor]]; 
[scroll setCanCancelContentTouches:NO]; 
scroll.clipsToBounds = NO; 
scroll.indicatorStyle = UIScrollViewIndicatorStyleBlack; 

//Título 
CGRect tit =CGRectMake(5.0f, 0.0f, 315.f, 50.0f); 
UILabel *titulo=[[UILabel alloc] initWithFrame:tit]; 
titulo.text=[itemNew objectForKey:@"titulo"]; 
titulo.numberOfLines = 2; 
titulo.font=[UIFont fontWithName:@"Helvetica" size:16.0f]; 
titulo.textColor=[self getColor:@"00336E"]; 
[scroll addSubview:titulo]; 
[titulo release]; 

//Entradilla 
float altura_entradilla=calcLabel([itemNew objectForKey:@"entradilla"], [UIFont boldSystemFontOfSize:16], 50, 315.0f); 
CGRect ent_frame = CGRectMake(5.0f, 50.0f, 315.0f,altura_entradilla); 
UILabel *entradilla=[[UILabel alloc] initWithFrame:ent_frame]; 
entradilla.text=[itemNew objectForKey:@"entradilla"]; 
entradilla.numberOfLines=4; 
entradilla.font=[UIFont fontWithName:@"Helvetica" size:17.0f]; 
entradilla.textColor=[UIColor blackColor]; 
[scroll addSubview:entradilla]; 
[entradilla release]; 

NSString *cuerpo=[itemNew objectForKey:@"cuerpo"]; 

[scroll setContentSize:CGSizeMake(320.0f,40000.0f)]; 
[scroll setScrollEnabled:YES]; 

webView = [[UIWebView alloc] initWithFrame:CGRectMake(5.0f, altura_entradilla+50, 315.0f, 900)];  
[webView loadHTMLString:cuerpo baseURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]]; 
webView.detectsPhoneNumbers=NO; 
webView.delegate=self; 
[webView setScalesPageToFit:NO]; 
[scroll addSubview:webView]; 

webView.backgroundColor=[UIColor blackColor]; 
webView.userInteractionEnabled=NO; 
[webView release]; 

if (altura_webview>900) { 
    UIWebView *webView2 = [[UIWebView alloc] initWithFrame:CGRectMake(5.0f, altura_entradilla+50+900, 315.0f, 900)]; 
    [webView2 loadHTMLString:cuerpo baseURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]]; 
    webView2.detectsPhoneNumbers=NO; 
    webView2.delegate=self; 
    [webView2 setScalesPageToFit:NO]; 
    [scroll addSubview:webView2]; 
    webView2.backgroundColor=[UIColor yellowColor]; 
    webView2.userInteractionEnabled=NO; 
    [webView2 release]; 
} 

self.view=scroll; 
+0

我不知道这是否会工作,但是可以将UIText和UIButton插入到UIWebView中吗? – Antonio 2009-04-21 16:16:20

+0

WebView具有webView.userInteractionEnabled = YES;这样所有的视图都可以通过UIScrollView一起滚动。 – Antonio 2009-04-22 10:45:49

回答

0
  1. 使用一个以上的UIWebViews中作为

  2. 是否使用loadHTMLString将内容添加到webView的身体吗? 尝试loadRequest方法。没有与1,024像素没有问题,当您使用的loadRequest

+0

嗨:我们使用的是loadHTMLString,因为HTML存储在本地变量中(保存在以前的会话中)。 loadRequest只能在从URL加载时使用,对吗? 问题似乎是,当滚动由父级UIScroll处理,而不是由UIWebView处理时,它会施加1024px的限制。 – Antonio 2009-04-22 09:20:38

+0

嗯... 在我目前的项目中,我使用contentSize.height超过40000px的UIScrollViews。 (许多webViews,标签和ImageViews),滚动没有任何问题。但如果我尝试创建UIWebView最高,然后1024px我有问题 loadRequest可以用来从本地文件加载数据 – oxigen 2009-04-22 11:35:48

1

检查您的UIScrollView的contentSize

我还没有听说过1000点的限制(或者在我的应用程序中看到它有更大的视图)。

0

我有同样的问题,我阅读并尝试了这个线程的一些技巧,但既不加载内容通过loadHTMLString,也没有使用[_webView setNeedsDisplay]确实改变了我的任何东西。 (我应该尝试加载更多UIWebViews中,但我懒惰:)

我用用滚动视图代表一个快速和肮脏的修复,其中的伎俩:

@interface ArticleViewController : UIViewController <UIScrollViewDelegate> 

再火起来在初始化的看法

_scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
self.view = _scrollView; 
_scrollView.delegate = self; 

,并使用delgate的方法来重绘webView的,因为它显示了

- (void) scrollViewDidEndDragging: (UIScrollView *) scrollView willDecelerate: (BOOL) willDecelerate 
{ 
    CGRect frame = _webView.frame; 
    frame.size = CGSizeMake(frame.size.width, frame.size.height + 1); 
    _webView.frame = frame; 
} 

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 
{ 
    CGRect frame = _webView.frame; 
    frame.size = CGSizeMake(frame.size.width, frame.size.height + 1); 
    _webView.frame = frame; 
} 
0

当你说:

我们试图打破身体分成几个900px高的网页视图,但第二,第三等得到削除(你可以看到的backgroundColor,而不是内容)...

在我看来,其他人已经遇到了这个问题(我再也找不到帖子了),实际上UIWebviews似乎只使用一个HTML解释器。这意味着如果一个UIWebView加载HTML内容,其他UIWebView将不加载任何内容。

为了解决这个问题,您需要使用UIWebView的委托方法:didFinishLoad,并在此之后开始加载其他网页浏览。

请注意,我不确定我在说什么,因为我没有自己尝试,但它可能是一个解决方案。

0

标记为答案的帖子在其最后的评论中有一个链接。这是解决这个问题的方法。我有这个问题,并调用[[webView _documentView] _webCoreNeedsDisplay];在那两位代表解决了它。干杯。