首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

手势坐标,该怎么处理

2012-09-15 
手势坐标拖拽手势能否 当拖动的时候能否获得两个相邻手势点之间的距离呢是不是可以设置一个中间变量来计算

手势坐标
拖拽手势能否 当拖动的时候能否获得两个相邻手势点之间的距离呢 是不是可以设置一个中间变量来计算得到。

[解决办法]
如果你用使用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));
}

热点排行