Sanbrother
Sanbrother

Reputation: 621

How can I detect whether a UIWebView is zooming?

every one:

I can enable zooming by setting scalesPageToFit to YES. But, how can I know whether UIWebView is zooming?

Does anyone know that?

Thanks in advance.

Upvotes: 3

Views: 1132

Answers (2)

SpaceDust__
SpaceDust__

Reputation: 4914

http://www.seeques.com/19639347/how-to-detect-zoom-scale-of-uiwebview.html

In my case I had to add a scrolview var and scrolviewdelegate,then set that scrolview to webview's scrolview to be able to call scrolviewdidendzooming method

Upvotes: 0

Sanbrother
Sanbrother

Reputation: 621

Resolved.

add a new property to XXXViewController to store current zoom scale (compared to initial scale)

@property (nonatomic, assign) float zoomScale;

set initial value of zoomScale at some proper place (e.g. viewDidLoad?)

self.zoomScale = 1.0f;

update zoom scale when the scale of ScrollView is changed (the ScrollView of UIWebView)

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{
    self.zoomScale *= scale;
}

if zoomScale is within certain range (almost 1.0), the WebView is not zooming

if(self.zoomScale - 1.0 < 0.001 && self.zoomScale - 1.0 > - 0.001) {
    // Not zooming
}

And, if you want to change the scale, you should

- (void)changeWebViewScale:(float)scale
{
    [self.webView.scrollView setZoomScale:scale / self.zoomScale animated:YES];
}

Upvotes: 3

Related Questions