2010-11-11 80 views
3

我有一個應用程序使用UIViewController在UIWebView中顯示文章,其中一些文件有圖像。我有它設置,這樣,當被點擊圖像調用UIWebView不自動調整大小以適合屏幕

- (void)displayImage:(NSInteger)i { 
ImageViewController * imageVC = [[ImageViewController alloc] initWithImageId:i]; 
[self.navigationController pushViewController:imageVC animated:YES]; 
[imageVC release]; 

}

此加載另一個UIViewController中。 我所有的觀點都很好地迴應了旋轉。 ImageViewController保持圖像的比例,我的ArticleViewController用文本填充屏幕。但是,只要我在查看ImageViewController的同時將屏幕旋轉到橫向模式並按下後退按鈕。之前的UIViewController不正確地進行自動修改,增加了文本的字體大小,而不是將更多的單詞放在一行上。

編輯:

這是一篇文章視圖控制器:

This is an article view controller

這是出現在當您單擊圖像ImageViewController:

ImageViewCOntroller - portrait

現在,如果我們在這裏改變方向...

ImageViewCOntroller - landscape

並點擊後退按鈕,文章內容被不適當地調整大小以適應窗口。

ArticleViewCOntroller - landscape bad

這可以通過關閉iPhone的兩倍予以糾正。這是這篇文章在景觀中的樣子。

ArticleViewCOntroller - landscape good

問題有事情做與UIWebView中不恰當地自動調整大小時它是當前不可見。我能做些什麼來解決這個問題?

+0

您是否找到了解決方案? – 2013-05-18 12:50:51

回答

5

您需要在Interface Builder中這樣做

點擊你的UIWebView並按下Apple-3來調出「Size Inspector」。

在「自動調整」下,確保選中裏面的兩個箭頭。這將確保視圖大小始終最大化到其容器。 例如:

+1

我已經完成了這項工作,除了我在原始問題中解釋的情況外,它工作良好。有更多的建議嗎? – Tozar 2010-11-12 18:11:38

1

您可以通過相加依賴於設備的方向不同的CSS樣式改變它在服務器端

/* Landscape */ 
@media screen and (min-width: 321px) 
{ 
    body{ 
    width: 320px; 
    }  
} 
/* Landscape */ 
@media screen and (min-width: 321px) 
{ 
    body{ 
    width: 480px; 
    }  
} 

,或者你可以從客戶端視改變: 如果你的頁面已經得到了視元標籤:

<meta name="viewport" id="view" content="width=320px, minimum-scale=1.0, maximum-scale=1.0"> 

然後在你的代碼,你可以改變這種視每次方向變化:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
if(interfaceOrientation == UIDeviceOrientationLandscapeLeft)  
[uiwebview stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById(\"view\").setAttribute('content', 'width=480');"]]; 
} 
.... 

並在方向爲縱向時再次更改它

+0

解決方案的視口部分像魅力一樣工作。謝謝! – 2011-10-27 13:00:12

1

供將來參考。你可以用這個程序來做到這一點。

[webView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];

相關問題