UIScrollview中有多少contentOffset更改以进行缩放? [英] How much contentOffset changes in UIScrollview for zooming?

查看:154
本文介绍了UIScrollview中有多少contentOffset更改以进行缩放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在UIScrollview中,当我滚动/拖动时,我在scrollview contentOffset中进行了更改,这表示我在滚动视图中滚动/拖动了多少。通过这种方式,我更新了scrollview的子视图以进行滚动。



但是,当我缩放滚动视图(使用缩放缩放)时,滚动视图的contentOffsets也会更改。我不明白contentOffset已经改变了多少因为我无法将更改与zoomScale值相关联。那么,有没有想知道contentOffset中的变化是否有变焦?



我的目的是获取在缩放时拖动的contentOffset变化的值(这不是我得到的因为缩放内容偏移更改)以便我可以相应地更新我的scrollview的子视图。



我被困在这里。任何帮助将非常感谢。



谢谢



Shaikot

解决方案

我已经设置了一个小测试项目,看起来contentOffset乘以 zoomScale 。因此,如果您想要考虑到这一点,请在使用之前将其除以 zoomScale



也许最好用一个小例子说明:
我已经设置了一个scrollView,并添加了一个足够大的视图来平移和缩放位。对于那种观点,我添加了一个小红色视图,无论如何都要保持在同一位置。
我正在观察scrollView的contentOffset属性,我已经实现了这样:

  CGPoint contentOffset = self.scrollView.contentOffset; 
CGFloat zoomScale = self.scrollView.zoomScale;

self.moveView.frame = CGRectMake((contentOffset.x + 10)/ zoomScale,
(contentOffset.y + 10)/ zoomScale,
10,
10);

这使moveView保持在屏幕上的相同位置,仅在用户缩放时缩放。 / p>

我希望这会让事情稍微清楚一点,但如果我能做更多的事情,请告诉我。


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

解决方案

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 the zoomScale 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:

CGPoint contentOffset = self.scrollView.contentOffset;
CGFloat zoomScale = self.scrollView.zoomScale;

self.moveView.frame = CGRectMake((contentOffset.x+10)/zoomScale,
                                 (contentOffset.y+10)/zoomScale,
                                 10,
                                 10);

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.

这篇关于UIScrollview中有多少contentOffset更改以进行缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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