5

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.

Cherie CH.
  • 171
  • 2
  • 8
  • What kind of elements are you trying to track in this way (buttons, custom views, etc.)? – Boris Dušek Nov 21 '15 at 18:08
  • Any kind of element actually. All elements that can be navigated to, from navigation bar to buttons. Is there something else missing that I'm supposed to implement? I tried it out in VoiceOver mode but these methods don't seem to be called when I swipe to land on another element (nav bar button, button). – Cherie CH. Nov 22 '15 at 06:51
  • @CherieCH. Are you sure that you've overridden these methods on an accessibility element? Do you see it highlighted by the VoiceOver cursor? – Justin Nov 22 '15 at 20:42
  • Hi Justin, what do you mean by highlighted? Currently, the elements are "boxed" in VoiceOver mode (the default look when VoiceOver is activated). I don't see the print lines though if that is what you're asking. So I don't think these methods have been overridden, but I don't know why :/ – Cherie CH. Nov 24 '15 at 02:51

2 Answers2

3

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.

ManuelMB
  • 1,254
  • 2
  • 8
  • 16
0

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.

XLE_22
  • 5,124
  • 3
  • 21
  • 72