如果您的 UIScrollView 已经处于该缩放级别,则 zoomToRect 不执行任何操作 [英] zoomToRect does nothing if your UIScrollView is already at that zoomlevel

查看:31
本文介绍了如果您的 UIScrollView 已经处于该缩放级别,则 zoomToRect 不执行任何操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我在 UIScrollView 中发现了一个错误,但我想检查其他人是否在观察同样的事情,以及它是否是预期的行为.

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.

我有一个 UIScrollView 并且正在尝试使用 zoomToRect 设置它正在查看的内容.这很好用.如果我然后拖动视图使其在别处寻找,然后使用相同的值触发 zoomToRect 它什么都不做.zoomToRect 命令仅在需要调整 zoomScale 时执行某些操作,如果需要平移,则视图只是静止不动.由于用户可以捏来放大或缩小,我只是希望使用 zoomToRect 而不必仔细检查 zoomLevels 是否会有所不同.

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?

***按要求添加代码

第一次调用 zoomToRect

First call to zoomToRect

[myScrollView zoomToRect:zoomToRect animated:YES];

View 正确瞄准了 UIScrollView 中我想要的点

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

现在让用户在屏幕上拖动并移动 UIScrollView 正在查看的点.不进行缩放,只进行平移.

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

现在再次调用 zoomToRect,使用相同的矩形

Now call zoomToRect again, with the same rect

[myScrollView zoomToRect:zoomToRect animated:YES];

什么都没发生.

推荐答案

Apple 表示这是 UIScrollView 的一个已知错误,将在未来版本中修复.

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

这篇关于如果您的 UIScrollView 已经处于该缩放级别,则 zoomToRect 不执行任何操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆