我正在开展一个辅助功能项目,segmentedController
中有一个NavigationBar
。几乎所有事情都工作正常,直到焦点出现在中间(2/3)SegmentedController
。它不会说accessibilityLabel ..
查看我的代码。
我正在使用NSNotifications
让'UIAccessibilityPostNotification'知道何时关注:
func chatLijst() {
let subViews = customSC.subviews
let lijstView = subViews.last as UIView
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, lijstView)
}
func berichtenLijst() {
let subViews = customSC.subviews
let messageView = subViews[1] as UIView
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, messageView)
}
func contactenLijst() {
let subViews = customSC.subviews
let contactenView = subViews.first as UIView
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, contactenView)
}
func setupSegmentedController(){
let lijst:NSString = "Lijst"
lijst.isAccessibilityElement = false
lijst.accessibilityLabel = "Lijst met gesprekken"
let bericht:NSString = "Bericht"
bericht.isAccessibilityElement = false
bericht.accessibilityLabel = "Bericht schrijven"
let contacten:NSString = "Contacten"
contacten.isAccessibilityElement = false
contacten.accessibilityLabel = "Contacten opzoeken"
let midden:CGFloat = (self.view.frame.size.width - 233) / 2
customSC.frame = CGRectMake(midden, 7, 233, 30)
customSC.insertSegmentWithTitle(lijst, atIndex: 0, animated: true)
customSC.insertSegmentWithTitle(bericht, atIndex: 1, animated: true)
customSC.insertSegmentWithTitle(contacten, atIndex: 2, animated: true)
customSC.selectedSegmentIndex = 0
customSC.tintColor = UIColor.yellowColor()
customSC.isAccessibilityElement = true
self.navigationController?.navigationBar.addSubview(customSC)
}
修正
奇怪的是,我必须在setup func中重构subViews数组,并用新的UIAccessibilityPostNotification
数组替换segmentsView
对象。
func chatLijst() {
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, segmentsViews[0])
}
// Restructure subviews....
segmentsViews = [customSC.subviews[2], customSC.subviews[1], customSC.subviews[0]]
答案 0 :(得分:2)
我正在使用NSNotifications来让UIAccessibilityPostNotification'知道何时集中注意力
唐'吨。这是构建自定义可访问控件的一种糟糕方式,更重要的是它可能会让用户感到困惑。屏幕改变通知不仅仅改变焦点,它还播放特定声音,向用户指示屏幕内容已经改变。
相反,我建议您将要显示为可访问性元素的子视图设置为具有自己标签和特征的可访问性元素,然后依靠操作系统来聚焦和激活它们,或者实现{{1在自定义控件中使用协议,然后依靠操作系统来聚焦和激活它们。