通过按钮放大点击Web视图iPad应用程序

时间:2013-07-03 06:18:41

标签: ipad uiwebview

在网页浏览中,我的代码是`静态浮动i = 1.5;

if(i<=7.5)
{
    [btnZoom setEnabled:YES];
    objWebView.transform = CGAffineTransformMakeScale(1+i,1+i);
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.0f];
    [UIView commitAnimations];
    i=i+1.5;
    NSLog(@"i===============%f",i);
}

if(i==7.5)
{
    NSLog(@"i===============%f",i);
    [btnZoom setEnabled:NO];
    i=1.5;
}

objWebview是网页视图的对象。我点击了缩放页面以适应webview的属性,但我必须放大按钮点击。 (我是iPhone新手)

通过此代码,它会被放大,但放大后我的网页内容会变得模糊。

1 个答案:

答案 0 :(得分:0)

有两种方法可以按代码库缩放UIWebView。

在UIWebView中提供缩放UIScrollView

此选项适用于iOS 5.0和&gt;

- (void)viewDidLoad
{
  NSString *urlAddress = @"<website url address here>";
  NSURL *url = [NSURL URLWithString:urlAddress];
  NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]
  [webView loadRequest:requestObj];  
  webView.delegate = self;
  webLookupView.scalesPageToFit = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)theWebView
{
  CGSize contentSize = theWebView.scrollView.contentSize;
  CGSize viewSize = self.view.bounds.size;

  float rw = viewSize.width / contentSize.width;

  theWebView.scrollView.minimumZoomScale = rw;
  theWebView.scrollView.maximumZoomScale = rw;
  theWebView.scrollView.zoomScale = rw;  
}

缩放网页本身

在UIWebViewDelegate方法– webViewDidFinishLoad:

NSString *jsCommand = [NSString stringWithFormat:@"document.body.style.zoom = 1.5;"];
[theWebView stringByEvaluatingJavaScriptFromString:jsCommand];

希望这会对你有所帮助。