ZoomToRect does nothing if your UIScrollView is already at that zoom level

I think I found an error in UIScrollView, but I want to check if other people are observing the same thing and if this is the expected behavior.

I have a UIScrollView and am trying to set what it is looking at using zoomToRect. It works great. If I then dragged the view so that it looks elsewhere and then ran zoomToRect with the same values, it does nothing. The zoomToRect command does something only if the scaling needs to be adjusted, if the pan is all that is needed, the view just sits motionless. Since the user could pinch to zoom in or out, I was just hoping to use zoomToRect, and you don't need to double-check that the ZoomLevels will be different.

Has anyone else experienced this? If this happens like this or is it a mistake?

*** Adding code as requested

First call to zoomToRect

[myScrollView zoomToRect:zoomToRect animated:YES]; 

Correctly look at the point in the UIScrollView that I wanted it to be

Now let the user drag and drop the screen that the UIScrollView is looking at. No scaling, only panning.

Now call zoomToRect again, with the same direct

 [myScrollView zoomToRect:zoomToRect animated:YES]; 

Nothing happens.

+4
source share
2 answers

Apple stated that this is a known bug with UIScrollView and will be fixed in a future version.

https://devforums.apple.com/message/158712#158712

At the same time, I worked on it as follows

 float zoomBefore = myScrollView.zoomScale; [myScrollView zoomToRect:zoomToRect animated:YES]; float zoomAfter = myScrollView.zoomScale; if (zoomBefore == zoomAfter) { [myScrollView setContentOffset:imageCoords animated:YES]; } 
+3
source

The default value of maximumZoomScale is 1.0. Therefore, when we double-click, we do not zoom in on the image. set maximumZoomScale as follows:

 myScrollView.maximumZoomScale = 5.0f; 
-2
source

Source: https://habr.com/ru/post/1299091/


All Articles