无法正确获取 UISwipeGestureRecognizer 方向 [英] Couldn't get UISwipeGestureRecognizer direction correctly

查看:30
本文介绍了无法正确获取 UISwipeGestureRecognizer 方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写代码以在视图上上下移动我的两个手指以更改某些状态.代码如下:

I'm writing code to move my two fingers up or down on a view to change some status. The code as below:

UISwipeGestureRecognizer *aSwipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
[aSwipeGesture setDirection:UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown];
aSwipeGesture.numberOfTouchesRequired = 2;
[self.View addGestureRecognizer:aSwipeGesture];


- (void)swipeGesture:(UISwipeGestureRecognizer *)sender {
    NSLog(@"Swipe received.");
    if (sender.direction==UISwipeGestureRecognizerDirectionUp) {
        NSLog(@"swipe up");
    } else if (sender.direction==UISwipeGestureRecognizerDirectionDown) {
        NSLog(@"swipe down");
    }
}

然而,我能收到的唯一打印日志是 Swipe 收到,如下所示.我无法收到向上或向下滑动的消息,我错过了什么吗?谢谢

However the only print log I could receive was Swipe received as below shows. I couldn't get the message for swipe up or swipe down, did I miss anything? Thanks

ViewController.m:228    Swipe received.
ViewController.m:228    Swipe received.
ViewController.m:228    Swipe received.
ViewController.m:228    Swipe received.
ViewController.m:228    Swipe received.
ViewController.m:228    Swipe received.

更新:我必须用两根手指才能完成滑动操作.

Updated: I have to use two fingers to finish the swipe action.

推荐答案

试试这个

UISwipeGestureRecognizer *aSwipeGestureUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
[aSwipeGesture setDirection:UISwipeGestureRecognizerDirectionUp];
aSwipeGestureUp.numberOfTouchesRequired = 2;
[self.View addGestureRecognizer:aSwipeGestureUp];

UISwipeGestureRecognizer *aSwipeGestureDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
[aSwipeGestureDown setDirection:UISwipeGestureRecognizerDirectionDown];
aSwipeGestureDown.numberOfTouchesRequired = 2;
[self.View addGestureRecognizer:aSwipeGestureDown];

这篇关于无法正确获取 UISwipeGestureRecognizer 方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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