使用情节提要板在WatchKit上检测所有四个方向上的滑动

使用情节提要板在WatchKit上检测所有四个方向上的滑动

本文介绍了使用情节提要板在WatchKit上检测所有四个方向上的滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to detect the swipes on the AppleWatch on all four directions. Yet I am not clear how to assign many values to the direction of the WKSwipeGestureRecognizer I inserted in the Storyboard. I tried with:

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

被编译器普遍接受,不同于使用按位|,但是使用此配置,功能:

that was funnily accepted by the compiler, differently of using the bitwise |, but, using this configuration, function:

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

}

很少被调用,当它是滑动时,方向始终是正确的.

is very seldom called and when it is the swiper.direction is invariably .right.

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

Apple is very cryptic at:https://developer.apple.com/reference/watchkit/wkswipegesturerecognizer/1650828-directionby saying:

没有透露具体方法.

推荐答案

1)从右侧的实用程序"框中选择WKSwipeGestureRecognizer

1) Select WKSwipeGestureRecognizer from Utilities box on the right side

2)在属性检查器中,选中开始延迟触摸",然后选择所需的滑动"类型

2) From the attributes inspectors, check "Delays touches began" and select "Swipe" type that you need

-

3) +将IBAction拖动到您的viewController并实现功能

3) + drag IBAction to your viewController and implement function

这篇关于使用情节提要板在WatchKit上检测所有四个方向上的滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 02:57