Reputation: 4510
There are a lot of questions with zooming in UIWebView, but I could not find an answer to mine.
I've got ViewController with WebView. I load an SVG-file into this WebView, and I want to zoom in by tapping on it. Here is the code:
@interface ViewController : UIViewController <UIGestureRecognizerDelegate>
{
IBOutlet MyWebView *webView;
UITapGestureRecognizer *doubleTapRecognizer;
CGFloat k;
}
...
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"map" withExtension:@"svg"]]];
webView.scalesPageToFit = YES;
webView.scrollView.maximumZoomScale = 512;
webView.scrollView.minimumZoomScale = 0.1;
doubleTapRecognizer.numberOfTapsRequired = 2;
doubleTapRecognizer.numberOfTouchesRequired = 1;
doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
doubleTapRecognizer.delegate = self;
doubleTapRecognizer.enabled = YES;
[webView addGestureRecognizer:doubleTapRecognizer];
k = 1;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
- (void)doubleTap:(UITapGestureRecognizer*)sender
{
if (sender.state == UIGestureRecognizerStateEnded)
{
k = 10;
// No one does not work correctly
[webView.scrollView setZoomScale:k animated:YES];
// [webView setContentScaleFactor:k];
// [webView.scrollView setContentScaleFactor:k];
// webView.scrollView.zoomScale = k;
// [webView.scrollView zoomToRect:CGRectMake(webView.bounds.origin.x, webView.bounds.origin.y, webView.bounds.size.width/k, webView.bounds.size.height/k) animated:YES];
}
}
Now WebView is zooming in by the tap, but only x2 and no more. What is wrong and how could I zoom it x10?
Upvotes: 1
Views: 888
Reputation: 23359
Have you tried pinching ?
It's not because you've set the max zoom to be 512 or 10 that tapping twice will zoom to that level, what it means is tapping onto a small element in the web view, this will zoom in to fill the available space of the web view, regardless of the zoom value, up until the max zoom value.
So something appearing to occupy half the screen will make the zoom be x2, smaller would be more.
Upvotes: 1