Closed. This question is off-topic。它目前不接受答案。
想改进这个问题吗?Update the question所以堆栈溢出的值小于aa>。
5年前关闭。
这是我的课。不知为什么,上,左,右工作都很好。唐似乎永远不会被认出来。
第一部分是viewDidLoad的一部分。我包括了整个功能“responseToSwipeGesture”
// Part of viewDidLoad
        // Setup gesture recognizers
        var swipeRight = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
        swipeRight.direction = UISwipeGestureRecognizerDirection.Right
        self.view.addGestureRecognizer(swipeRight)

        var swipeDown = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
        swipeDown.direction = UISwipeGestureRecognizerDirection.Down
        self.view.addGestureRecognizer(swipeDown)

        var swipeLeft = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
        swipeLeft.direction = UISwipeGestureRecognizerDirection.Left
        self.view.addGestureRecognizer(swipeLeft)

        var swipeUp = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
        swipeDown.direction = UISwipeGestureRecognizerDirection.Up
        self.view.addGestureRecognizer(swipeUp)

//viewDidLoad段结束
func respondToSwipeGesture(gesture: UIGestureRecognizer) {

    if let swipeGesture = gesture as? UISwipeGestureRecognizer {

        switch swipeGesture.direction {
        case UISwipeGestureRecognizerDirection.Right:
            println("Swiped right")
        case UISwipeGestureRecognizerDirection.Down:
            println("Swiped down")
        case UISwipeGestureRecognizerDirection.Up:
            println("Swiped up")
        case UISwipeGestureRecognizerDirection.Left:
            println("Swiped left")
        default:
            break
        }
    }
}

最佳答案

在代码中输入错误

var swipeUp = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeDown.direction = UISwipeGestureRecognizerDirection.Up
self.view.addGestureRecognizer(swipeUp)

swipeDown而不是swipeUp

关于ios - 为什么这些手势识别器中的四个会起作用? (关闭不起作用),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24312503/

10-14 23:09