问题
I want to know when a user shifts the focus away from an accessibility element. I have tried overriding the accessibilityElementDidLoseFocus()
and accessibilityElementDidBecomeFocused()
methods but the methods doesn't seem to be called upon when I navigate to other elements in VoiceOver accessibility mode. I have no idea what is wrong. Is there anything else that I should do to activate these methods?
override func accessibilityElementDidBecomeFocused() {
println("become focused")
}
override func accessibilityElementDidLoseFocus() {
println("lose focus")
}
The current development is on iOS 8.1, using Swift.
回答1:
Try using:
isAccessibilityElement = true
The default value for this property is false unless the receiver is a standard UIKit control, in which case the value is true.
Assistive applications can get information only about objects that are represented by accessibility elements. Therefore, if you implement a custom control or view that should be accessible to users with disabilities, set this property to true. The only exception to this practice is a view that merely serves as a container for other items that should be accessible. Such a view should implement the UIAccessibilityContainer protocol and set this property to false.
回答2:
More than 2 years after the initial question but I hope this will help anyway.
The problem occurs because you may have overriden these methods in your view controller, you should implement your code in your accessibility element directly.
You could create a class to define the accessibility element or just make an extension of its superclass where you put the UIAccessibilityFocus
overriden functions.
来源:https://stackoverflow.com/questions/33845837/uiaccessibilityfocus-protocol-not-working