获取嵌套在UIScrollView中的UIImageView中两个CGPoints之间的距离

时间:2013-01-09 03:16:05

标签: ios uiscrollview uiimageview distance cgpoint

CGRect screenSize = [[UIScreen mainScreen]bounds];
CGFloat screenWidth = screenSize.size.width;
CGRect visibleRect;
    visibleRect.origin = scrollView.contentOffset;
    visibleRect.size = imageView.frame.size;
    CGPoint midPoint = CGPointMake(visibleRect.origin.x + visibleRect.size.width / 2, visibleRect.origin.y + visibleRect.size.height / 2);
CGPoint place = CGPointMake(class.xValue, class.yValue);

xValue和yValue是'在类中声明的int。

-(int)distanceFrom:(CGPoint)point1 to:(CGPoint)point2{
CGFloat xDist = ((point2.x) - (point1.x));
CGFloat yDist = ((point2.y) - (point1.y));
return (sqrt((xDist * xDist) + (yDist * yDist)));
}

问题在于,一旦我通过在应用程序中滚动来更改zoomScale并调用该方法,数字会发生剧烈变化(~1000像素)。如何考虑zoomScale?提前致谢, 亚历

1 个答案:

答案 0 :(得分:0)

当您放大时,距离方法的结果乘以滚动视图的zoomScale。如果您想获得实际距离,请尝试将距离除以滚动视图的zoomScale