当前位置: 代码迷 >> Iphone >> 手势坐标,该怎么处理
  详细解决方案

手势坐标,该怎么处理

热度:16   发布时间:2016-04-25 06:23:13.0
手势坐标
拖拽手势能否 当拖动的时候能否获得两个相邻手势点之间的距离呢 是不是可以设置一个中间变量来计算得到。

------解决方案--------------------
如果你用使用touchesBegain等方法实现拖拽,则可以如下实现:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 记录开始时的位置,_ptMarked需要被定义为成员变量
_ptMarked = [[touches anyObject] locationInView:self];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint ptCurrent = [touches anyObject] locationInView:self];

// 计算当前触点和初始触点间的距离
CGFloat distance = sqrt(pow((ptCurrent.x-_ptMarked.x),2.0)+pow((ptCurrent.y-_ptMarked.y), 2.0));
}
  相关解决方案