3

我尝试通过设置 UIWebview 的最大缩放比例

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

但做不到。如果任何人有任何想法,请告诉..

4

1 回答 1

1

按照步骤 :

1)添加静态const float zoomSc = 3.0;还要UIScrollViewDelegate.h文件中添加

2) yourWebView.scrollView.delegate = self;

3)添加下面的scrollView委托方法

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

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

编辑range:更改zoom factor

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()"];
}
于 2013-06-03T06:07:00.337 回答