Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

309
Visualizações
How to disable one of multiple gesture recognizers?

I am trying to disable 1 of 3 gesture recognizers I have added to a view, does anyone know what the correct code is?

Here's what i have so far:

// the gesture recognizer i'm trying to disable

    let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:)))
    myImageView1.addGestureRecognizer(tap)


// the code to disable it

    let allGRs = [currentView.gestureRecognizers]

    for g in allGRs {

        if let g as? UITapGestureRecognizer {
            g.isEnabled = false
        }

    }

Thankyou!

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Hope this can help you!

  1. Add unique name to your UITapGestureRecogniser

    let tapName = "100" //Any unique name
    func addGestureRecognisers() {
        let view = UIView() // Your view in your context. I just added to test my code
        let tap = UITapGestureRecognizer(target: self, action: action: #selector(self.handleTap(_:)))
        tap.name = tapName 
        view.addGestureRecognizer(tap)
    }
    
  2. Filter UITapGestureRecognisers and then Filter the result by name.

    func disableTapGesture(from view: UIView) {
        view.gestureRecognizers?.filter({$0.name == tapName}).first?.isEnabled = false
    }
    
over 4 years ago · Santiago Trujillo Relatório

0

You should assign the name property to your gesture recognizer.

tap.name = "myTapGesture"

And later you can cycle through the recozniers and only disable the one that you want.

for aRecognizer in view.gestureRecognizers {
   if let name = aRecognizer.name {
       if name == "myTapGesture" {
           aRecognizer.isEnabled = false
       }
   }
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda