Davao
Davao

Reputation: 33

accessibilityElementDidBecomeFocused doesn't get called

I´m trying to get the information if an element get focused with voiceover. So I override the accessibilityElementDidBecomeFocused method, but this gets never called. Did I forget something?

override func viewDidLoad() {
    super.viewDidLoad()        
    viewArray.append(UIView())
    viewArray.append(UIView())        
    viewArray[0].frame = CGRectMake(20, 210, 100, 100)
    viewArray[0].isAccessibilityElement = true
    self.view.addSubview(viewArray[0])

    viewArray[1].frame = CGRectMake(220, 220, 100, 100)
    viewArray[1].isAccessibilityElement = true
    self.view.addSubview(viewArray[1])

}

//never called
override func accessibilityElementDidBecomeFocused(){
    println("accessibilityElementDidBecomeFocused")
}

Upvotes: 1

Views: 4496

Answers (2)

Anit Kumar
Anit Kumar

Reputation: 8153

accessibilityElementDidBecomeFocused is not calling, Because where you are adding subviews, that class isAccessibilityElement is false. If you want to access the accessibilityElementDidBecomeFocused for subview. You can create the custom class and call this func.

You can check this link for more details about accessibilities: https://a11y-guidelines.orange.com/mobile_EN/dev-ios.html

Upvotes: 0

David Rönnqvist
David Rönnqvist

Reputation: 56635

It's not being called because your view controller is not an accessibility element. You should override it in the custom view subclass.

Just to clarify: you won't get that callback whenever an accessibility element becomes focused, but instead the element itself will get that callback when it becomes forces.

The reason why you can override it (the reason why UIViewController implements it) is that it's an informal protocol, a category implemented on NSObject, meaning that every NSObject implements those methods.

Upvotes: 8

Related Questions