Question

I'm trying to apply a scale transformation to some CALayers based on the zoomScale of a UIWebView's internal UIScrollView. However, I'm noticing the minimumZoomScale/maximumZoomScale values are constantly changing as zoom is performed. Which is curious because that's not how a UIScrollView performs when used individually. Normally, the UIScrollView's zoomScale fluctuates between the minimum and maximum zoom scale values that have been explicitly set.

Here's a log taken from the UIWebView internal UIScrollView

2014-02-21 15:19:36.335 CCCanvasSample[31484:70b] MIN SCALE 1.000000 //Zoomed all the way out
2014-02-21 15:19:36.335 CCCanvasSample[31484:70b] ZOOM SCALE 1.000000
2014-02-21 15:19:36.336 CCCanvasSample[31484:70b] MAX SCALE 7.200000
2014-02-21 15:19:41.433 CCCanvasSample[31484:70b] MIN SCALE 1.000000
2014-02-21 15:19:41.433 CCCanvasSample[31484:70b] ZOOM SCALE 3.179087
2014-02-21 15:19:41.434 CCCanvasSample[31484:70b] MAX SCALE 7.200000
2014-02-21 15:19:46.417 CCCanvasSample[31484:70b] MIN SCALE 0.314534
2014-02-21 15:19:46.418 CCCanvasSample[31484:70b] ZOOM SCALE 2.127526
2014-02-21 15:19:46.418 CCCanvasSample[31484:70b] MAX SCALE 2.264642
2014-02-21 15:19:49.555 CCCanvasSample[31484:70b] MIN SCALE 0.147830
2014-02-21 15:19:49.555 CCCanvasSample[31484:70b] ZOOM SCALE 1.064375
2014-02-21 15:19:49.556 CCCanvasSample[31484:70b] MAX SCALE 1.064375
2014-02-21 15:19:51.598 CCCanvasSample[31484:70b] MIN SCALE 0.138889
2014-02-21 15:19:51.598 CCCanvasSample[31484:70b] ZOOM SCALE 1.000000
2014-02-21 15:19:51.599 CCCanvasSample[31484:70b] MAX SCALE 1.000000 //Zoomed all the way in

This is a log from a regular UIScrollView:

2014-02-21 15:24:10.342 CCCanvasSample[31540:70b] MIN SCALE 0.033884
2014-02-21 15:24:10.344 CCCanvasSample[31540:70b] ZOOM SCALE 0.033884
2014-02-21 15:24:10.344 CCCanvasSample[31540:70b] MAX SCALE 0.500000
2014-02-21 15:24:14.595 CCCanvasSample[31540:70b] MIN SCALE 0.033884
2014-02-21 15:24:14.596 CCCanvasSample[31540:70b] ZOOM SCALE 0.055143
2014-02-21 15:24:14.596 CCCanvasSample[31540:70b] MAX SCALE 0.500000
2014-02-21 15:24:16.440 CCCanvasSample[31540:70b] MIN SCALE 0.033884
2014-02-21 15:24:16.440 CCCanvasSample[31540:70b] ZOOM SCALE 0.355361
2014-02-21 15:24:16.441 CCCanvasSample[31540:70b] MAX SCALE 0.500000
2014-02-21 15:24:18.503 CCCanvasSample[31540:70b] MIN SCALE 0.033884
2014-02-21 15:24:18.504 CCCanvasSample[31540:70b] ZOOM SCALE 0.500000
2014-02-21 15:24:18.504 CCCanvasSample[31540:70b] MAX SCALE 0.500000

I've also noticed that the UIWebView will reset the min/max zoom scales for its UIScrollView if I try to set them myself. Can anyone shed some light on this behavior?

Was it helpful?

Solution

After struggling with this for a bit I was able to get the accurate zoom scale for UIWebView:

CGFloat accurateZoomScale = webView.scrollView.zoomscale/webView.scrollView.minimumZoomScale;

Still unsure about the specifics of how UIWebView manipulates its internal UIScrollView but hopefully this will save someone some time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top