2015-12-12 41 views
0

我有一個webView,當內容最初加載它看起來很完美,並很好地適應,但只要它完成加載它自動放大方式。有沒有辦法阻止?我試過更多的組合,比我可能在這裏發佈。從自動縮放停止WebView

很多謝謝。

我正在使用的代碼是非常直截了當:

NSString *urlString = @"some_url"; 
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]; 
[cell.webView loadRequest:request]; 
+0

的可能的複製[UIWebView中禁用縮放時scalesPageToFit是ON](http://stackoverflow.com/questions/9062195/uiwebview-disable-zooming-when-scalespagetofit-is-on) –

+0

試過頁已經,沒有工作。 – tgwaste

+0

你可以添加一些更多的滾動相關的代碼,我反應重複 –

回答

0

這裏就是你要做的:

在擁有web視圖您的UI控制器,使它成爲一個UIWebViewDelegate。然後,您可以設置要加載的URL,將委託作爲控制器:

NSString *urlAddress = @"http://dl.dropbox.com/u/50941418/2-build.html"; 
NSURL *url = [NSURL URLWithString:urlAddress]; 
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
[webView loadRequest:requestObj]; 
webView.delegate = self; 

最後落實webViewDidFinishLoad:正確設置縮放級別:

此選項將適用於從iOS的5.0和>

- (void)webViewDidFinishLoad:(UIWebView *)theWebView{ 
CGSize contentSize = theWebView.scrollView.contentSize; 
CGSize viewSize = theWebView.bounds.size; 
float rw = viewSize.width/contentSize.width; 
theWebView.scrollView.minimumZoomScale = rw; 
theWebView.scrollView.maximumZoomScale = rw; 
    theWebView.scrollView.zoomScale = rw; 
} 

我希望這有助於...

選項B,你可以嘗試改變日e HTML(這個例子完成了這項工作,但從HTML解析的角度來看,它並不完美。我只想說明我的觀點。它確實適用於您的示例,也可能適用於大多數情況。 40的插圖可能會以編程方式檢測到,我沒有試圖研究。

NSString *urlAddress = @"http://dl.dropbox.com/u/50941418/2-build.html"; 
NSURL *url = [NSURL URLWithString:urlAddress]; 
NSString *html = [NSString stringWithContentsOfURL:url encoding:[NSString defaultCStringEncoding] error:nil]; 
NSRange range = [html rangeOfString:@"<body"]; 
if(range.location != NSNotFound) { 
// Adjust style for mobile 
float inset = 40; 
NSString *style = [NSString stringWithFormat:@"<style>div {max-width: %fpx;}</style>", self.view.bounds.size.width - inset]; 
html = [NSString stringWithFormat:@"%@%@%@", [html substringToIndex:range.location], style, [html substringFromIndex:range.location]]; 
} 
[webView loadHTMLString:html baseURL:url]; 
+0

沒有工作。它是否有所不同,webView正在調用網絡攝像頭流? – tgwaste