2

I'm trying to show a UIAlertContoller and dismiss it when VoiceOver user performs a scrub gesture:

override func accessibilityPerformMagicTap() -> Bool {
        showPopup()
        return true
    }

    override func accessibilityPerformEscape() -> Bool {
        print("close")
        return true
    }

    func showPopup(){
        baseAlert = UIAlertController(title: "Popup", message: "Choose an option", preferredStyle: .Alert)
        let firstAction = UIAlertAction(title: "method 1", style: .Default) { (alert: UIAlertAction!) -> Void in
            print("one")
        }

        let secondAction = UIAlertAction(title: "method 2", style: .Default) { (alert: UIAlertAction!) -> Void in
            print("two")
        }

        let thirdAction = UIAlertAction(title: "method 3", style: .Default) { (alert: UIAlertAction!) -> Void in
            print("three")
        }

        let closeAction = UIAlertAction(title: "Close", style: .Destructive) { (alert: UIAlertAction!) -> Void in
            print("close")
            self.accessibilityPerformEscape()
        }

        baseAlert.addAction(firstAction)
        baseAlert.addAction(secondAction)
        baseAlert.addAction(thirdAction)
            baseAlert.addAction(closeAction)

        baseAlert.accessibilityHint = "Pop menu"
        presentViewController(baseAlert, animated: true, completion:
            {
                    self.textField.becomeFirstResponder()
            }
        )


    }

The above code shows the UIAlertController and when I perform scrub gesture it does not react to it, but when the alert is not shown or dismissed escape gesture works.

Maysam
  • 7,246
  • 13
  • 68
  • 106
  • Have you found out a solution for your question at the time you could share with us, please? – XLE_22 Aug 14 '23 at 06:47

2 Answers2

2

you need to add the code to dismiss your UIAlertController in accessibilityPerformEscape(), returning true is not enough.

Ocunidee
  • 1,769
  • 18
  • 20
1

I think that your scrub gesture works when there's no alert view because you are in a controller (navigation controller ???) that natively takes into account this VoiceOver gesture.

However, you were following the right method for you alert view by overriding the accessibilityPerformEscape method : the problem dealt with its 'empty' implementation that could be adjusted according to this detailed answer by adding a dismiss order.

XLE_22
  • 5,124
  • 3
  • 21
  • 72