2012-06-20 49 views
3

我試圖通過設置最大變焦倍數爲UIWebView的

 webView.scrollView.maximumZoomScale=2.0; 
     webView.scrollView.minimumZoomScale=1.0; 

但不設定最大變焦倍數爲UIWebView中能夠做到的。如果任何機構有任何想法,請告訴..

+0

由「不能做」 1. web視圖不能放大是什麼意思? 2.最大規模不能限制網絡視圖? – TedCheng

回答

1

以下步驟:

1)添加靜態const float zoomSc = 3.0;此外,在文件.h

2)yourWebView.scrollView.delegate = self添加UIScrollViewDelegate;

3)下方添加滾動視圖委託方法

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{ 

    if (scale > zoomSc) 
    { 
    scrollView.zoomScale= zoomSc; 
    } 
} 

EDIT:更改的zoom factor

range添加這些以下在UIWebViewDelegate's方法。

注意:不要忘記設置委託UIWebView

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
    //restrict zoomscale by adding javascript code 
    //make changes to only maximum-scale value as i have set it to 10.0. 
    NSString *strJSFunction = [NSString stringWithFormat:@"function increaseMaxZoomFactor(){ var element = document.createElement('meta'); element.name = \"viewport\"; element.content = \"maximum-scale=10.0\"; var head = document.getElementsByTagName('head')[0]; head.appendChild(element); }"]; 

    [webView stringByEvaluatingJavaScriptFromString:strJSFunction]; 
    [webView stringByEvaluatingJavaScriptFromString:@"increaseMaxZoomFactor()"]; 
}