0

In web view my code is`static float 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 is the object of web view.my scales page to fit property of webview is clicked but I have to zoom in on the button click. (I am new in iPhone)

By this code it is getting zoomed-in, but my webview contents are getting blurred when zoomed in.

4

1 回答 1

0

There are two ways to zoom your UIWebView by codebase.

Zoom UIScrollView available in UIWebView

This option will applicable from iOS 5.0 and >

- (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;  
}

Zoom Webpage itself

In UIWebViewDelegate method – webViewDidFinishLoad:

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

Hope this helps you.

于 2013-07-03T06:46:45.347 回答