有没有办法以编程方式设置辅助功能焦点(App Store-safe)?任何帮助将不胜感激。
答案 0 :(得分:37)
专注于你可以打电话的元素。
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, self.myFirstElement);
否则,对于iOS 8+,使用accessibilityElements设置元素顺序,它将自动关注列表中的第一个元素
self.accessibilityElements = @[myFirstView, mySecondButton, myThirdLabel]
答案 1 :(得分:5)
extension UIAccessibility {
static func setFocusTo(_ object: Any?) {
if UIAccessibility.isVoiceOverRunning {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) {
UIAccessibility.post(notification: .layoutChanged, argument: object)
}
}
}
}
添加此扩展名,然后通过传递您要关注的视图来调用它。如果要在使用标签栏导航时更改焦点,可以从viewWillAppear调用此方法。如果没有0.7或更大的延迟,此代码将无法在任何init方法中使用。
答案 2 :(得分:1)
这是Swift代码:
UIAccessibility.post(notification: .screenChanged, argument: <theView>)
示例用法
let titleLabel = UILabel()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIAccessibility.post(notification: .screenChanged, argument: titleLabel)
}
答案 3 :(得分:0)
UIAccessibility.post(notification: .layoutChanged, argument: toast)
toast.becomeFirstResponder()
toast.isAccessibilityElement = true
toast.accessibilityTraits = .staticText //Traits option ie .header, .button etc
toast.accessibilityLabel = "Accessibility label to be read by VoiceOver goes here"
哪里:
toast
是我的 UIView(在特定情况下触发的弹出窗口)View
toast
),VoiceOver 将读取 accessibilityLabel