UIScrollview 中的 contentOffset 因缩放而变化了多少?
在 UIScrollview 中,当我滚动/拖动时,滚动视图 contentOffset 发生了变化,它代表了我在滚动视图中滚动/拖动的量。通过这种方式,我已经更新了scrollview的子视图以进行滚动。
但是,当我缩放滚动视图(使用捏缩放)时,滚动视图的 contentOffsets 也会更改。我不明白 contentOffset 发生了多少变化,因为我无法将这些变化与 ZoomScale 值联系起来。那么,是否有办法知道 contentOffset 的变化以进行缩放?
我的目的是获取缩放时拖动的 contentOffset 更改的值(这不是我由于缩放内容偏移更改而得到的),以便我可以相应地更新滚动视图的子视图。
我被困在这里了。任何帮助将非常感激。
谢谢沙科特
In UIScrollview, when I scroll/drag, I got changes in scrollview contentOffset which represent how much I had scrolled/dragged in the scrollview. By this way, I have updated the subview of scrollview for scrolling.
But, when I zoom the scrollview (using pinch zooming), the contentOffsets of the scrollview is also changed. I do not understand how much contentOffset has changed because I can not relate the changes with zoomScale value. So, is there anyway to know changes in contentOffset for zooming?
My intention is get the value of contentOffset changes for dragging while zooming (which is not I am getting because of zooming content offset changes) so that I can update my scrollview's subview accordingly.
I am stuck in here. Any help will be very much appreciated.
thanks
Shaikot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经设置了一个小型测试项目,看起来 contentOffset 乘以
zoomScale
。因此,如果您想考虑这一点,只需在使用它之前除以zoomScale
即可。也许最好用一个小例子来说明:
我已经设置了一个滚动视图,并添加了一个足够大的视图,可以平移和缩放一点。对于该视图,我添加了一个小的红色视图,无论如何我都希望将其保留在同一位置。
我正在观察scrollView的contentOffset属性,并且我已经像这样实现了它:
这使moveView保持在屏幕上的相同位置,仅在用户缩放时缩放它。
我希望这能让事情变得更清楚,但请告诉我是否可以提供更多帮助。
I've set up a small test project, and it looks like the contentOffset is multiplied by the
zoomScale
. So if you want to account for that, just divide it by thezoomScale
before using it.Maybe it's best to illustrate with a small example:
I've set up a scrollView, and added a view that's big enough to pan around and zoom a bit. To that view, I've added a small red view that I want to keep in the same position, no matter what.
I'm observing the contentOffset property of the scrollView, and I've implemented it like this:
This keeps the moveView in the same position on the screen, only scaling it when the user zooms.
I hope this clears thing up a bit, but let me know if I can do more to help.