在iOS 14中,UIBarButtonItem是否不再支持AccessibilityLabel? [英] Is UIBarButtonItem no longer supporting accessibilityLabel in iOS 14?

查看:0
本文介紹了在iOS 14中,UIBarButtonItem是否不再支持AccessibilityLabel?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

更新:此錯誤已在iOS 14.5中修復


我在UINavigationController中嵌入了以下類:

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let barButton = UIBarButtonItem(title: "Save", style: .plain, target: nil, action: nil)
        barButton.accessibilityLabel = "Save meeting"
        navigationItem.rightBarButtonItem = barButton
    }
}

運行iOS 14.4時,可訪問性標簽被忽略,只有可見標題由畫外音宣布。然而,在iOS 13.7上,可訪問性標簽被正確使用。UIBarButtonItem用法是否已更改,或者這是iOS錯誤?

上下文屏幕截圖:

推薦答案

當我必須實現UIBarButtonItem時,我總是遵循these instructions以確保a11y將是穩定的和完全正常的。??

我不知道這種情況是錯誤還是由于新的iOS版本而導致的一種倒退,但在導航欄按鈕中實現11y作為定制是一個完美的方式,可以避免遇到任何不幸的意外,即使它看起來像是一個樣板解決方案。??

我已經創建了一個空白項目,在導航控制器中嵌入了一個簡單的視圖控制器,其中顯示了如下所示的右側欄按鈕:

class NavBarViewController: UIViewController {

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
    
        var a11yRightBarButton: UIBarButtonItem?
    
        let a11y = UILabel()
        a11y.text = "OK"
        a11y.sizeToFit()
        a11y.isUserInteractionEnabled = true //Mandatory to use the 'tap gesture'.
    
        a11yRightBarButton = UIBarButtonItem(customView: a11y)
    
        let tap = UITapGestureRecognizer(target: self,
                                         action: #selector(validateActions(info:)))
        a11yRightBarButton?.customView?.addGestureRecognizer(tap)
    
        a11yRightBarButton?.isAccessibilityElement = true
        a11yRightBarButton?.accessibilityTraits = .button
        a11yRightBarButton?.accessibilityLabel = "validate your actions"
    
        navigationItem.rightBarButtonItem = a11yRightBarButton
    }

    @objc func validateActions(info: Bool) -> Bool {
        print("hello")
        return true
    }
}

右欄按鈕顯示確定,畫外音顯示";在iOS 14.4和Xcode 12.4下驗證您的操作。??

按照這個原理,您可以使用UIBarButtonItem來支持iOS 14中的accessibilityLabel屬性。??

這篇關于在iOS 14中,UIBarButtonItem是否不再支持AccessibilityLabel?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持IT屋!

查看全文
登錄 關閉
掃碼關注1秒登錄
發送“驗證碼”獲取 | 15天全站免登陸
全免费A级毛片免费看无码播放