swift - 使用 Storyboard检测 WatchKit 上所有四个方向的滑动

标签 swift watchkit swipe apple-watch

我正在尝试检测 AppleWatch 在所有四个方向上的滑动。但是我不清楚如何为我插入 Storyboard 中的 WKSwipeGestureRecognizer 的方向分配许多值。我试过:

swiper.direction = [.right , .left ,  .up , .down]

这被编译器有趣地接受了,与使用按位 | 不同,但是,使用这个配置,函数:

@IBAction func swipe(_ sender: Any) {
    switch swiper.direction {
    case WKSwipeGestureRecognizerDirection.right:
        print("Swiped right")
    case WKSwipeGestureRecognizerDirection.down:
        print("Swiped down")
    case WKSwipeGestureRecognizerDirection.left:
        print("Swiped left")
    case WKSwipeGestureRecognizerDirection.up:
        print("Swiped up")
    default:
        break
    }

}

很少被调用,当它是滑动器时。方向总是正确的。

Apple 在以下方面非常神秘: https://developer.apple.com/reference/watchkit/wkswipegesturerecognizer/1650828-direction 通过说:

"The default value of this property is right. You may specify more than one direction to track swipes in multiple directions with the same gesture recognizer."

没有透露如何。

最佳答案

无论如何,完全忽略 Apple 所说的,在 Storyboard中放置四个 WKSwipeGestureRecognizer,每个具有不同的方向和目标。

关于swift - 使用 Storyboard检测 WatchKit 上所有四个方向的滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40029319/

相关文章:

ios - 访问 AddressBook 是否需要征求用户的许可?

swift - 在 WKInterfaceTable 行中放置一个图像和两个标签

ios - 如何检测 Spritekit 节点上的滑动?

iOS:在 subview 内滑动手势

andengine - 在手指滑动下方添加视觉效果,像水果忍者和引擎一样的三角形条

ios - swift:将屏幕方向重置为纵向

iOS 标签可见性切换没有动画

Swift2 UI 测试 - 等待元素出现

ios - 苹果 watch 模拟器问题

ios - 我可以创建一个没有 Storyboard的 WatchKit 应用程序(完全在代码中)吗?