2011-10-21 40 views
1

這個問題是讓我瘋了。UIWebView:適合框架查看大小,允許在UISplitViewController框架內滾動

我有我試圖讓填補一個UISplitViewController右側衆目睽睽一個UIWebView:

CGSize boundsSize = self.view.bounds.size; 
self.webView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, boundsSize.width, boundsSize.height)] autorelease]; 
self.webView.delegate = self; 
self.webView.opaque = NO; 
self.webView.backgroundColor = [UIColor redColor]; 
self.webView.allowsInlineMediaPlayback = YES; 
self.webView.dataDetectorTypes = UIDataDetectorTypeAddress | UIDataDetectorTypeLink | UIDataDetectorTypePhoneNumber; 
self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin; 
[self.view addSubview:webView]; 

首先,我怎麼解釋使幀大小適合視圖時我不知道方向?我可以自動調整大小到合適的尺寸嗎?

接下來,當我將我的HTML加載到我的webView中時,我希望框架大小保持不變(就像UIScrollView一樣),但是可以使用該框架滾動該新內容。有些內容更長,有些則不是。所以,我試圖調整框架,但這只是使我的框架更大,而不是我的內容大小。

- (void)webViewDidFinishLoad:(UIWebView *)aWebView { 

    // Calculate the size of our webview 
    CGRect frame = aWebView.frame; 
    frame.size.height = 1; 
    aWebView.frame = frame; 
    CGSize fittingSize = [aWebView sizeThatFits:CGSizeZero]; 
    frame.size = fittingSize; 
    aWebView.frame = frame; 

}//end 

這不可能嗎?我是否需要將webView放入UIScrollView中,並在每次將其加載到我的webView時將contentSize設置爲新內容的高度?

回答

-4

看來我不得不手動調節負載我的框架:

// Orientation 
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 

    // Create frame 
    CGRect frame; 
    if (UIInterfaceOrientationIsLandscape(orientation)) { 
     frame = CGRectMake(0, 0, 748, 1024); 
    } else { 
     frame = CGRectMake(0, 0, 768, 1022); 
    }//end 
0
+0

對不起,我已經有了,只是忘了在這裏發佈。添加到我的示例中。 –

+0

你可能會遇到這個問題在iOS 5中.http://stackoverflow.com/questions/7767302/how-to-inform-the-parent-viewcontroller-about-the-changed-screen-orientation-in – logancautrell

2

我認爲這是所有你需要做這項工作。

[articleWebView sizeThatFits:CGSizeZero];