开发者

zoomToRect does nothing if your UIScrollView is already at that zoomlevel

I think I have found a bug in UIScrollView, but I want to check if other people are observing the same thing and if it is expected behaviour.

I've got a UIScrollView and am trying to set what it is looking at using zoomToRect. That works fine. If I then drag the view so it's looking elsewhere and then trigger the zoomToRect with the same values it does nothing. The zoomToRect command only does something if the zoomScale needs to be adjusted, if a pan is all that is needed the view just sits still. Since a user could pinch to zoom in or out I was just hoping to use zoomToRect and not have to double check the zoomLevels would be different.

has anyone else experienced this? Should it happen that way or is it a bug?

***Adding code as requested

First call to zoomToRect

[myScrollView zoomToRect:zoomToRect animated:YES];

View aimed correctly at point in the UIScrollView that I wanted it to be

Now let the user drag on the screen and move the point the UIScrollView is looking at. No zooming occurs, only panning.

Now call zoomToRect 开发者_开发百科again, with the same rect

[myScrollView zoomToRect:zoomToRect animated:YES];

Nothing happens.


Apple have said this is a known bug with UIScrollView and will be fixed in a future release.

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

In the mean time I have worked around this as follows

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


Default maximumZoomScale is 1.0. So it doesn't zoom when we double click. set maximumZoomScale like this:

myScrollView.maximumZoomScale = 5.0f;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜