UISwipeGestureRecognizer.Direction.down

votos
0

Eu configurei um GestureRecognizer para esquerda / direita, mas eu também gostaria de adicionar um GestureRecognizer para baixo (mas não para cima). Quando eu aplicar o seguinte, as obras deslize para cima como esperado na tela do dispositivo; no entanto, UISwipeGestureRecognizer.Direction.down não faz nada.

func addGesture() {
    // Gesture recognizers
    let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(self.swipeAction(swipe:)))
    leftSwipe.direction = UISwipeGestureRecognizer.Direction.left
    self.view.addGestureRecognizer(leftSwipe)

    let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(self.swipeAction(swipe:)))
    rightSwipe.direction = UISwipeGestureRecognizer.Direction.right
    self.view.addGestureRecognizer(rightSwipe)

    let downSwipe = UISwipeGestureRecognizer(target: self, action: #selector(self.swipeAction(swipe:)))
    downSwipe.direction = UISwipeGestureRecognizer.Direction.down
    self.view.addGestureRecognizer(downSwipe)
}

Estou faltando um identificador no segue storyboard ou há alguma outra coisa que eu preciso fazer para o dispositivo para reconhecer um golpe baixo?

Publicado 20/09/2018 em 04:35
fonte usuário
Em outras línguas...                            


1 respostas

votos
0

func addGesture() {
    // Gesture recognizers

    let directions: [UISwipeGestureRecognizer.Direction] = [.left, .right, .down]
    for direction in directions {
        let gesture = UISwipeGestureRecognizer(target: self, action: #selector(self.swipeAction(swipe:)))
        gesture.direction = direction
        self.view.addGestureRecognizer(gesture)
    }

}

@objc func swipeAction(swipe:UISwipeGestureRecognizer) {
    if let swipeGesture = swipe as? UISwipeGestureRecognizer {
        switch swipeGesture.direction {


        case UISwipeGestureRecognizer.Direction.left:
            print("Swiped left")    
            let vc = self.storyboard!.instantiateViewController(withIdentifier: "ViewController5") as! ViewController5
            vc.hero.modalAnimationType = .fade
            hero.replaceViewController(with: vc)

        case UISwipeGestureRecognizer.Direction.right:
            print("Swiped right")
            let vc = self.storyboard!.instantiateViewController(withIdentifier: "ViewController") as! ViewController
            vc.hero.modalAnimationType = .fade
            hero.replaceViewController(with: vc)

        case UISwipeGestureRecognizer.Direction.down:
            print("Swiped down")
            let vc = self.storyboard!.instantiateViewController(withIdentifier: "ViewController3") as! ViewController3
            vc.hero.modalAnimationType = .pull(direction: .down)
            hero.replaceViewController(with: vc)

        default:
            break
        }
    }
}
Respondeu 24/09/2018 em 05:22
fonte usuário

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more