accessibilityPerformEscape不会忽略UIAlertController

时间:2016-04-25 05:37:55

标签: swift uiaccessibility

我正在尝试显示UIAlertContoller并在VoiceOver用户执行修正手势时将其关闭:

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()
            }
        )


    }

上面的代码显示UIAlertController,当我执行擦除手势时,它不会对它做出反应,但是当警报未显示或解除时,转义手势会起作用。

2 个答案:

答案 0 :(得分:1)

您需要添加代码以在accessibilityPerformEscape()中关闭您的UIAlertController,返回true是不够的。

答案 1 :(得分:0)

我认为当没有警报视图时,您的滑动手势可以工作,因为您位于本机会考虑此VoiceOver手势的控制器(导航控制器???)中。

但是,您通过覆盖accessibilityPerformEscape方法遵循了正确的警报视图方法:该问题涉及其“空”实现,可以通过添加{ {1}}订单。