在将 UIAccessibility 焦点更改为其他元素之前再次防止语音播报

Prevent Voice over announcement again before changing UIAccessibility focus to other element

我有一个视图。在双击动作我隐藏它。 但在发布到其他视图之前,它会再次宣布。 下面是代码片段。

func setUpAccessibility() {
                    let tapGesture = UITapGestureRecognizer(target: self, action: #selector(blockLabelViewSwipeGesture))
                    blockContainerView.accessibilityLabel = "Some text label"
                    blockContainerView.accessibilityHint = "Double tap to dismiss"
                    blockContainerView.isAccessibilityElement = true
                    blockContainerView.addGestureRecognizer(tapGesture)
}

    @objc private func blockLabelViewSwipeGesture(_ gestureRecognizer: UISwipeGestureRecognizer { 
             UIAccessibility.post(notification: .layoutChanged, argument: self.headerView)
            //Dismiss view 
            ///DO some work
}

解决这个问题。在 action 方法中,我们需要将 accessibilityLabel 设置为空,如果 accessibilityHint 存在,则将其设置为空 sting 。 下面是代码片段。

 @objc private func blockLabelViewSwipeGesture(_ gestureRecognizer: UISwipeGestureRecognizer { 
            blockContainerView.isAccessibilityElement = false
            blockContainerView.accessibilityLabel = ""
            blockContainerView.accessibilityHint = ""

           UIAccessibility.post(notification: .layoutChanged, argument: self.headerView)
            //Dismiss view 
            ///DO some work
}