UIScrollView:缩放后的内容偏移计算 [英] UIScrollView: content offset calculation after zoom
问题描述
在放大UIScrollView后,有人可以建议哪些公式用于内容偏移计算?让我们考虑以下示例:
我有一个内容视图大小为(1000,1000)的UIScrollView,然后如果我以编程方式 setZoomScale
到2.0和 scrollViewDidEndZooming:withView:atScale
方法我将有以下内容:
Could somebody advice which formula used to content offset calculation after zoom in UIScrollView? Let's consider following example:
I have a UIScrollView with content view in size (1000, 1000), then if I programmatically setZoomScale
to 2.0 and in scrollViewDidEndZooming:withView:atScale
method I will have the following:
contentSize before zoom = {1000, 1000}
contentOffset before zoom = {0, 0}
scale = 2.000000
contentSize after zoom = {2000, 2000}
contentOffset after zoom = {160, 230}
我需要知道contentOffset {160,230}的新值是如何计算的。在这种情况下,是否存在用于计算内容偏移的公式的依赖性?
I need to know how the new value of contentOffset {160, 230} calculated. Is there any dependency of formula that used to calculate the content offset in this case?
谢谢
推荐答案
这可能相关或不相关,但请注意,160x230是iPhone分辨率的一半,减去状态栏:320x460。尝试更改UIScrollView的框架或其超级视图的框架,看看它如何影响数字。
This may or may not be relevant, but note that 160x230 is half the resolution of the iPhone, less the status bar: 320x460. Try changing the UIScrollView's frame, or its superview's frame, and see how this affects the numbers.
编辑:想想看,它完全可以理解偏移是滚动视图大小的一半,因为它将在两个方向上均匀扩展。因此,公式为: contentOffset =(scrollView.frame.size.width / 2 *(scaleAfter - scaleBefore),scrollView.frame.size.height / 2 *(scaleAfter - scaleBefore))
。
EDIT: Come to think of it, it makes perfect sense that the offset is half the size of the scroll view, as it will expand equally in both directions. So, the formula would be: contentOffset = (scrollView.frame.size.width/2 * (scaleAfter - scaleBefore), scrollView.frame.size.height/2 * (scaleAfter - scaleBefore))
.
因此,如果比例为4.0f,则偏移量为:(320/2 *(4-1) ),460/2 *(4-1))=> (480,690)
。尝试4的等级,看看是否(480,690)出来。
Therefore, if the scale was 4.0f, the offset would be: (320/2 * (4-1), 460/2 * (4-1)) => (480, 690)
. Try a scale of 4 and see if (480, 690) comes out.
这篇关于UIScrollView:缩放后的内容偏移计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!