UIWebView的缩放不超过x2

时间:2011-12-01 14:43:32

标签: objective-c uiwebview zoom

关于缩放UIWebView有很多问题,但我找不到答案。

我有使用WebView的ViewController。我将SVG文件加载到此WebView中,我想通过点击它来放大。这是代码:

@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];
    }
}

现在,WebView正在通过点按放大,但只有x2而不是更多。有什么问题,我怎么能把它缩放x10?

1 个答案:

答案 0 :(得分:1)

你试过捏?

这不是因为您将最大缩放设置为512或10,因此点击两次将缩放到该级别,这意味着点击Web视图中的一个小元素,这将放大以填充可用空间无论缩放值如何,直到最大缩放值。网页视图。

所以看起来占据屏幕一半的东西会使缩放为x2,更小则会更多。