2012-04-13 46 views
0

我在UIScrollView中有一个彩色地图,并且试图采样该地图的一个像素的颜色。样本光罩位于滚动视图上方,而用户移动光罩下滚动视图的内容。iPhone iOS通过缩放在UIScrollView中计算位置

用户可以用水龙头手势放下十字线,但我想提供一个额外的选项来移动十字线下的视图。

我试图找出我如何理解放大视图的x,y坐标当前位于光罩下。迄今为止,这个逻辑还没有解决,特别是涉及到放大/缩小。

-(void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 

    CGPoint mapLocation = [tapGestureRecognizer locationInView:self.surfaceMap]; 

    NSLog(@"mapLocation (x,y) %.0f,%.0f",mapLocation.x,mapLocation.y); 

    NSLog(@"contentOffset (x,y) %.0f,%.0f",self.scrollView.contentOffset.x,self.scrollView.contentOffset.y); 

    //calculate where the marker is pointing to in the surface map while the scrollview is scrolling 

    int frameWidth = self.surfaceMap.frame.size.width; 
    int frameHeight = self.surfaceMap.frame.size.height; 

//this is what I'm trying to calculate 
    CGPoint trueLocation = CGPointMake(self.scrollView.contentOffset.x+frameWidth-self.surfaceMap.frame.origin.x, self.scrollView.contentOffset.y-self.surfaceMap.frame.origin.y); 
    NSLog(@"trueLocation (x,y) %.0f,%.0f",trueLocation.x,trueLocation.y); 

    [self colorOfPixelAtPoint:trueLocation]; 

} 

任何输入赞赏!

回答

1

您可以在UIView的这两种方法要在有看:

- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view; 
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view; 
+0

非常感谢,这个工作! – 2012-04-13 17:55:38