1

我用这两个函数来检测用户在uiview上慢慢拖拽

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

-(void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event

但是,我如何使用这两种方法来检测用户实际轻弹(快速翻转)uiview?

我如何区分轻弹和拖动?

非常感谢你的帮助!

正义便士

4

3 回答 3

4

你可以试试这样的使用-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event方法来标记beginPoint和beginTime;ues 方法来标记endPoint-(void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event和 endTime 。然后计算速度,你可以比较速度和你的阈值。(速度可能只计算水平或垂直)

于 2013-01-09T03:56:35.543 回答
1

我认为你应该检查手势识别器——它们需要大量的工作来区分不同的用户触摸。您所描述的是平移和滑动手势。有特定的手势识别器类来处理其中的每一个。UIGestureRecognizer 是父类,你应该先看看它。

于 2013-01-08T22:59:35.990 回答
1

Drag 和 Flick 通常以速度来区分 - 一种解决方案是创建基于距离公式的算法。

一个粗略的例子:

CGPoint pointOld = CGPointMake(0, 0); // Not sure if this is valid
CGPoint pointNew = CGPointMate(0, 0); // Just making holders for the
                                      // location of the current and previous touches

float timeInterval = 0.2f;
// However long you think it will take to have enough of a difference in
// distance to distinguish a flick from a drag

float minFlickDist = 100.0f;
// Minimum distance traveled in timeInterval to be considered a flick

- (void)callMeEveryTimeInterval
{
    // Distance formula
    float distBtwnPoints = sqrt( (pointNew.x - pointOld.x) * (pointNew.x - pointOld.x) - (pointNew.y - pointOld.y) * (pointNew.y - pointOld.y) );
    if (distBtwnPoints >= minFlickDist)
    {
        // Flick
    } else {
        // Drag
    }
}

我认为可能有用的东西的粗略草图 - 希望有帮助。

于 2013-01-09T00:46:01.857 回答