[英]IOS: difference touches in view
I have this code, where location and previousLocation are two 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];
ok this is a part of code that is inside "touchmoved" of my GLPaint application; 好的,这是我的GLPaint应用程序“触摸移动”内的代码的一部分; but my problem is that I want shift location and previousLocation in a fix point, this point in a vertex of an imageview (I do it because I drag an image when i touch view) and value of this point could be as:
但是我的问题是我想在固定点上移动位置和previousLocation,该点在imageview的顶点中(之所以这样做,是因为当我触摸视图时拖动图像),而该点的值可能是:
CGPoint *vertex = (imageView.center.x-100, imageView.center.y+100);
so my code change in: 所以我的代码更改为:
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];
location can be changed easily but my problem now is previousLocation, how I can change it? 位置可以轻松更改,但我现在的问题是previousLocation,如何更改它? Then my question is...what's the way to know differences from location to previousLocation?
然后我的问题是...如何知道位置与先前位置之间的差异? How can I calculate its difference?
如何计算差异? So if I know the dinamic difference I can set a correct shift previousLocation...
因此,如果我知道动态差异,则可以设置一个正确的shift previousLocation ...
这是解决方案:
CGPoint gap = CGPointMake(cur.x - prev.x, cur.y - prev.y);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.