2009-04-21 46 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];在那兩位代表解決了它。乾杯。