0

我在 UIScrollView 中有一个颜色图,并且正在尝试对该图的像素颜色进行采样。示例标线位于滚动视图上方,而用户将滚动视图的内容移动到标线下方。

用户可以通过轻击手势放下标线,但我想提供一个额外的选项来移动标线下的视图。

我试图找出如何理解缩放视图的 x,y 坐标当前位于 reticle 下。到目前为止,这个逻辑让我难以理解,特别是因为涉及到放大/缩小。

-(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];

}

任何输入表示赞赏!

4

1 回答 1

1

You may want to a have look at these two methods in UIView:

- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;
于 2012-04-13T16:48:27.750 回答