iOS开发:手势识别与定位功能详解
1. 手势识别基础
在iOS开发中,每个 UITouch 对象都能知晓其在视图中的当前位置和先前位置。为了比较角度,我们需要存储用户上一次触摸屏幕时的当前点和先前点,以便比较当前线条与先前线条并检查角度。同时,我们还声明一个实例变量来记录用户手指拖动的距离。若手指移动距离不足10像素(即 kMinimumCheckMarkLength 定义的值),则无论角度是否在正确范围内都无关紧要,这样可避免大量误判。
2. 手势识别方法实现
为处理发送给手势识别器的触摸事件,需添加以下两个方法:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];
lastPreviousPoint = point;
lastCurrentPoint = point;
lineLengthSoFar = 0.0;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event
超级会员免费看
订阅专栏 解锁全文
1405

被折叠的 条评论
为什么被折叠?



