0

我有这段代码,其中 location 和 previousLocation 是两个 CGPoint:

    CGRect  bounds = [self bounds];
UITouch *touch = [[event touchesForView:self] anyObject];
    CGPoint point = [touch locationInView:self];
    location = CGPointMake(point.x,point.y);
    location.y = bounds.size.height - location.y;
    CGPoint prev = [touch previousLocationInView:self];
    previousLocation = CGPointMake(prev.x, prev.y);
previousLocation.y = bounds.size.height - previousLocation.y;
    [self renderLineFromPoint:previousLocation toPoint:location];

好的,这是我的 GLPaint 应用程序“touchmoved”中的一部分代码;但我的问题是我想在一个固定点移动位置和previousLocation,这个点在一个imageview的顶点(我这样做是因为我在触摸视图时拖动一个图像),这个点的值可能是:

CGPoint *vertex = (imageView.center.x-100, imageView.center.y+100);

所以我的代码更改为:

    CGRect  bounds = [self bounds];
UITouch *touch = [[event touchesForView:self] anyObject];
    //CGPoint point = [touch locationInView:self];
    location = CGPointMake(vertex.x,vertex.y);
    location.y = bounds.size.height - location.y;
    //CGPoint prev = [touch previousLocationInView:self];
    previousLocation = CGPointMake(prev.x, prev.y);        <---- ?????
previousLocation.y = bounds.size.height - previousLocation.y;
    [self renderLineFromPoint:previousLocation toPoint:location];

位置可以轻松更改,但我现在的问题是previousLocation,我该如何更改?那么我的问题是......知道从位置到previousLocation的差异的方法是什么?我如何计算它的差异?因此,如果我知道动态差异,我可以设置正确的 shift previousLocation ...

4

1 回答 1

0

这是解决方案:

CGPoint gap = CGPointMake(cur.x - prev.x, cur.y - prev.y); 
于 2012-11-21T14:47:58.533 回答