2015-12-12 37 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