IOS:差异化的视角

时间:2012-11-14 09:39:37

标签: ios location cgpoint

我有这个代码,其中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”内部代码的一部分;但我的问题是我想要一个固定点的shift位置和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的差异的方法是什么?我该如何计算其差异?因此,如果我知道dinamic的区别,我可以设置一个正确的转移previousLocation ...

1 个答案:

答案 0 :(得分:0)

这是解决方案:

CGPoint gap = CGPointMake(cur.x - prev.x, cur.y - prev.y);