ios - accessibilityPerformMagicTap() not getting called - Stack Overflow

I’ve overridden the accessibilityPerformMagicTap() function in a UIViewController subclass to detect th

I’ve overridden the accessibilityPerformMagicTap() function in a UIViewController subclass to detect the magic tap gesture for that view controller. However, when triggering the magic tap, the function is not being called.

How can I properly observe the magic tap gesture?

I also tried adding this function in AppDelegate, but it didn’t receive a callback either.

Note: I haven’t used the accessibilityPerformMagicTap() function anywhere else in my project.

Below i have attached the sample code.

class SecondaryVC : UIViewController{
    private var actionButton : UIButton = {
        let button = UIButton(type: .system)
        button.backgroundColor = .systemGreen
        button.setTitle("Add", for: .normal)
        button.layer.cornerRadius = 8
        return button
    }()

    override func viewDidLoad(){
        super.viewDidLoad()
        view.backgroundColor = .systemTeal

        //Suggestion from StackOverFlow (Can't access subviews)
        view.isAccessibilityElement = true
        view.accessibilityTraits = [.button]
        view.accessibilityLabel = "Secondary View focused"

        tabBarItem = UITabBarItem(title: "Secondary", image: UIImage(systemName: "square"), selectedImage: UIImage(systemName: "square.fill"))

        addSubViews()
    }

    override class func accessibilityPerformMagicTap() -> Bool {
        print(">>>> SecondaryVC accessibilityPerformMagicTap")
        return true
    }

    override class func accessibilityPerformEscape() -> Bool {
        print(">>>> secodaryVC EscapeAction")
        return true
    }

    private func addSubViews(){
        view.addSubview(actionButton)
        actionButton.translatesAutoresizingMaskIntoConstraints = false
        actionButton.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor,constant: 16).isActive = true
        actionButton.leadingAnchor.constraint(equalTo: view.leadingAnchor,constant: 16).isActive = true
        actionButton.trailingAnchor.constraint(equalTo: view.trailingAnchor,constant: -16).isActive = true
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745106874a4611611.html

相关推荐

  • ios - accessibilityPerformMagicTap() not getting called - Stack Overflow

    I’ve overridden the accessibilityPerformMagicTap() function in a UIViewController subclass to detect th

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信