如何检测滑动手势方向?

2024-01-24

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

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;
}
}

它不起作用:/


这是我的一个项目的示例:

    // ...

    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
    swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:swipeLeft];

    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self  action:@selector(didSwipe:)];
    swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:swipeRight];

    UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc]  initWithTarget:self action:@selector(didSwipe:)];
    swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
    [self.view addGestureRecognizer:swipeUp];

    UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
    swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
    [self.view addGestureRecognizer:swipeDown];

    // ...

- (void)didSwipe:(UISwipeGestureRecognizer*)swipe{

    if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
        NSLog(@"Swipe Left");
    } else if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {
        NSLog(@"Swipe Right");
    } else if (swipe.direction == UISwipeGestureRecognizerDirectionUp) {
        NSLog(@"Swipe Up");
    } else if (swipe.direction == UISwipeGestureRecognizerDirectionDown) {
        NSLog(@"Swipe Down");
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何检测滑动手势方向? 的相关文章

随机推荐

  • RSelenium 中的滚动页面

    如何使用以下命令手动滚动到页面底部 或顶部 RSelenium网络驱动程序 我有一个元素 仅当它在页面上可见时才可用 假设你有 library RSelenium startServer remDr lt remoteDriver remD
  • 使用 mutate 中的 distm 函数计算两点之间的距离

    我正在尝试计算两组经度和纬度坐标之间的距离 我正在使用 geosphere 包中的函数 distm 来执行此操作 如果我手动将值放入 distm 函数中 它可以正常工作 但我无法让它在我的 mutate 命令中工作 当在 mutate 函数
  • gwt编译错误

    Compiling module com sem Sem10 Finding entry point classes ERROR Unable to find type com sem client Sem10 ERROR Hint Pre
  • spring-boot-starter-oauth2-client、spring-cloud-starter-oauth2 和 spring-security-oauth2 之间有什么区别

    我正在为 OAUTH2 中的 client credentials 授予类型流开发客户端应用程序 我无法决定在我的项目中为此目的使用以下依赖项 spring boot starter oauth2 客户端 spring cloud star
  • Flutter:使用插件构建需要符号链接支持

    每当我尝试安装任何依赖项时 我都会在日志中收到以下错误pubspec yaml Building with plugins requires symlink support Please enable Developer Mode in y
  • 比使用“A UNION (B in A)”更高效的 SQL?

    编辑1 澄清 感谢您迄今为止的回答 反响令人欣慰 我想稍微澄清一下这个问题 因为根据答案 我认为我没有正确描述问题的一个方面 我确信这是我的错 因为我什至很难为自己定义它 问题在于 结果集应仅包含 tstamp 介于 2010 01 03
  • 如何在 iPhone 中的 uilabel 上显示倒计时?

    我在视图上有一个 uilabel 和一个 uislider 我想使用滑块设置标签的时间 滑块的范围是 00 00 00 到 03 00 00 意味着 3 小时 滑块上的间隔是 0 5 分钟 还有如何显示 我希望即使应用程序关闭 计时器也会运
  • Symfony2 在包和控制器之间传递数据

    这更像是一个 最佳实践 问题 而不是一个实际问题 我正在 Symfony 2 中开发一个项目 并且构建了一个包来处理我的所有 Web 服务 基本上 一个控制器获取一些 JSON 数据 将其发送到另一个控制器以检查其是否与所描述的格式匹配 然
  • 证书文件存在时出现“CryptographicException:找不到请求的对象”

    我有一个 p12证书文件 我像这样创建我的证书 var certificate new X509Certificate2 certFileLocation mySecret X509KeyStorageFlags Exportable Wh
  • 错误:“if”之前应有不合格的 id

    我用谷歌搜索了这个错误 直到我脸色发青 但无法将任何结果与我的代码联系起来 这个错误似乎通常是由于牙套 父母等放错位置或丢失造成的 我已经很长时间没有写过任何 C 了 所以我可能遗漏了一些明显的 愚蠢的东西 这是我正在编写的 Qt Mobi
  • Hadoop ChainMapper、ChainReducer [重复]

    这个问题在这里已经有答案了 我对 Hadoop 比较陌生 并试图弄清楚如何使用 ChainMapper ChainReducer 以编程方式链接作业 多个映射器 减速器 我找到了一些部分示例 但没有一个完整且有效的示例 我当前的测试代码是
  • 使用 url 参数时,iPhone 的 Web 应用程序从主屏幕切换到 Safari

    我为 iPhone 开发了一个网络应用程序 并将其添加为书签并添加到 iPhone 的主屏幕上 不过 我注意到它有一个问题 它会按预期工作 直到我导航到应用程序中具有查询字符串和参数的页面 例如 www mywebapp com page0
  • 在 calc() 中使用分数 (fr) 给出“无效的属性值”

    我正在尝试使用calc 使用 CSS 网格时在某些宽度上 所以我正在尝试的一件事是 grid template columns calc 1fr 50px calc 1fr 50px 因为我希望它是两个分数 但删除 50px 因为它用于填充
  • Meteor:从客户端上传文件到 Mongo 集合 vs 文件系统 vs GridFS

    Meteor 很棒 但它缺乏对传统文件上传的原生支持 有多种选项可以处理文件上传 来自客户 可以使用以下方式发送数据 Meteor call saveFile data 或 collection insert file data POST
  • 查找 maven 用于运行 testng 测试用例的类路径

    我可以使用 maven 的哪些选项来确定 maven 正在使用哪个类路径运行 testng 测试用例 您没有提供 Maven 版本 但至少在 3 x 也可能是 2 x 中您可以使用 X 调试 选项运行命令 这样 测试类路径就会在测试运行之前
  • 如何更改默认的WCF服务绑定?

    在我的 WCF 中 我有一些服务 其中之一必须对消息大小有更大的限制 因此我必须创建另一个绑定并更改配置 但是 我在 Web config 中看不到我的服务的任何配置 什么也没有 有什么是默认的吗 那么我可以在哪里更改服务绑定呢 在 WCF
  • 错误:无法访问 com.facebook.imagepipeline.animated.base.AnimatedImage 的 AnimatedImage 类文件未找到

    我收到错误 错误 无法访问 AnimatedImage 未找到 com facebook imagepipeline animated base AnimatedImage 的类文件 尝试运行时https github com WhatsA
  • 使用 C# 创建 Windows 窗体向导

    我是 C Net 中的 Windows 窗体应用程序创建向导的新手 所以我对向导创建没有任何想法 请给我一些关于创建多个向导的想法 问候 拉维 有很多方法可以做到 为每个向导步骤创建一个表单是可能的 但非常尴尬 而且丑陋的是 当用户改变步骤
  • VSTO:应用重点

    有人知道如何查看 VSTO 项目的 Excel 窗口是否处于活动 焦点状态吗 我正在寻找相当于System Windows Window IsActive 我也曾为此感到沮丧 您在 VSTO 应用程序中使用对话框吗 如果是这样 我所做的就是
  • 如何检测滑动手势方向?

    我需要检测我的滑动手势的方向 但我遇到了问题 手势有效 但我不知道如何检测方向 swipeGesture UISwipeGestureRecognizer alloc initWithTarget self action selector