如何检测滑动手势方向? [英] how detect swipe gesture direction?

查看:395
本文介绍了如何检测滑动手势方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检测我的滑动手势的方向,我遇到了问题。手势正在工作,但我不知道如何检测方向。
...

i need to detect direction of my swipe gesture and i've got problem with it. gesture is working, but i don't know how to detect direction. ...

swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(detectSwipe:)];
[swipeGesture setNumberOfTouchesRequired:1];
[swipeGesture setDirection:UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionUp];
[appView addGestureRecognizer:swipeGesture];

-(void)detectSwipe:(UISwipeGestureRecognizer *)recognizer { 
switch (recognizer.direction) {
    case UISwipeGestureRecognizerDirectionUp:
        NSLog(@"smth1");
        break;


    case UISwipeGestureRecognizerDirectionDown:
        NSLog(@"smth2");
    default:
        break;
}
}

它不起作用:/

推荐答案

方向属性仅定义可识别的允许的方向作为滑动,而不是特定滑动的实际方向。

The direction property only defines the allowed directions that are recognized as swipes, not the actual direction of a particular swipe.

最简单的方法是使用两个单独的手势识别器。您还可以在手势开始时以及以 locationInView:方法结束时检查触摸的位置。

The easiest would be to use two separate gesture recognizers instead. You could also inspect the location of the touch when the gesture starts and when it ends with the locationInView: method.

这篇关于如何检测滑动手势方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆