7

With VoiceOver switched-on, when focus comes on a UIButton/UITableViewCell/UICollectionViewCell, VoiceOver reads it's accessibility label once.

Then as soon as user double taps to select that UIButton/UITableViewCell/UICollectionViewCell, VoiceOver reads the same accessibility label again besides performing action (navigation etc) on UIButton/UITableViewCell/UICollectionViewCell selection.

I've searched a lot but not able to find a way to stop/disable VoiceOver reading accessibility label on UIButton/UITableViewCell/UICollectionViewCell selection.

Any help would be highly appreciated.

madlymad
  • 6,367
  • 6
  • 37
  • 68
Maverick
  • 3,209
  • 1
  • 34
  • 40
  • Did you ever find an answer to this? I'm running into the same issue. – Jan Feb 22 '17 at 16:39
  • 2
    Apologies for delayed response. I handled it by forced selection of another accessibility element. For example, after making selection from TableView/CollectionView, I'm supposed to navigate to new UI. What I'm doing is that I forcefully select left bar button item of navigation bar of new UI right after navigation is completed. Selection is made using `UIAccessibilityPostNotification`. This way, it starts reading newly selected item. Please see this [link](http://stackoverflow.com/questions/10659881/voiceover-force-an-accessibility-element-to-be-selected-after-a-screen-transiti) for selection – Maverick Mar 05 '17 at 13:06
  • @XLE_22 I had posted this question almost three years before your answer was posted so I never tried your solution but appreciate your contribution. I had already used a workaround mentioned right above your recent message that has received 2 upvotes as well, so apparently that helped others too. However I don't see any upvote on your answer from anyone else as well. – Maverick Mar 14 '23 at 22:26
  • Thanks Maverick for your return and your validated answer. My question only dealt with the fact that some solutions were found out for your problem with no validation... whatever it's mine or not. The goal is to info others that your initial question has a validated answer. – XLE_22 Mar 16 '23 at 15:57

3 Answers3

0

Let's see how to stop the VoiceOver accessibility reading for the UIButton and the UITableViewCell elements.

UIBUTTON : just create your own button class and override the accessibilityActivate method.

class BoutonLabelDoubleTap: UIButton {

    override func accessibilityActivate() -> Bool {
        accessibilityLabel = ""
        return true
    }
}

UITABLEVIEWCELL : two steps to be followed.

  • Create a custom UIAccessibilityElement overriding the accessibilityActivate method.

    class TableViewCellLabelDoubleTap: UIAccessibilityElement {
    
        override init(accessibilityContainer container: Any) {
            super.init(accessibilityContainer: container)
        }
    
        override var accessibilityTraits: UIAccessibilityTraits {
            get { return UIAccessibilityTraitNone }
            set {   }
        }
    
        override func accessibilityActivate() -> Bool {
            accessibilityLabel = ""
            return true
        }
    }
    
  • Use the previous created class to implement your table view cells in the view controller.

    class TestButtonTableViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
    
        @IBOutlet weak var myTableView: UITableView!
        @IBOutlet weak var bottomButton: UIButton!
    
        override func viewDidLoad() {
            super.viewDidLoad()
            myTableView.delegate = self as UITableViewDelegate
            myTableView.dataSource = self as UITableViewDataSource
        }
    
        func numberOfSections(in tableView: UITableView) -> Int {
            return 1
        }
    
        func tableView(_ tableView: UITableView,
                       numberOfRowsInSection section: Int) -> Int {
            return 2
        }
    
        func tableView(_ tableView: UITableView,
                       cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
            let zeCell = tableView.dequeueReusableCell(withIdentifier: "myPersoCell",
                                                       for: indexPath)
    
            zeCell.accessibilityElements = nil
            var elements = [UIAccessibilityElement]()
    
            let a11yEltCell = TableViewCellLabelDoubleTap(accessibilityContainer: zeCell)
            a11yEltCell.accessibilityLabel = "cell number " + String(indexPath.row)
            a11yEltCell.accessibilityFrameInContainerSpace = CGRect(x: 0,
                                                                    y: 0,
                                                                    width: zeCell.contentView.frame.size.width,
                                                                    height: zeCell.contentView.frame.size.height)
            elements.append(a11yEltCell)
            zeCell.accessibilityElements = elements
    
            return zeCell
        }
    }
    

I haven't tried for a UICollectionViewCell but it should be the same rationale as the UITableViewCell's.

Following these code snippets, you're now able to decide if VoiceOver should stop reading out the desired elements labels when selected.

XLE_22
  • 5,124
  • 3
  • 21
  • 72
  • How can we stop the voice over "1 of 10", "2 of 10" etc. Facing an issue in UIPickerView where it always says "1 of 10" whenever we swipe to any elment – Nishchith Jun 30 '21 at 11:35
  • 1
    @Nishchith I'm not sure you listen "1 over x" for each cell in this scrollable view example I provided, don't you? (more than 2 years now ⏳) I didn't make any test with a picker view and the only answer I provided is https://stackoverflow.com/a/61018428/3825084, sorry. – XLE_22 Jun 30 '21 at 17:05
  • Sure thanks. I am facing this issue of the current index not voicing out properly. It always says "1 of total" when I swipe. Do you have any idea how we can completely disable the voice over only when the picker swipe happens? On setting my own accessibilityLabel. It voices out accessibility label text and then the default one as well. https://stackoverflow.com/questions/68183280/uipickerview-accessibility-voiceover-issue – Nishchith Jul 01 '21 at 05:18
0

Swift 5

What worked for me was setting myElementIWantSilent.accessibilityTraits = .none

EDIT: I should note that these are also present:

viewContainingSilentElement.isAccessibilityElement = true
viewContainingSilentElement.accessibilityTraits = .image
viewContainingSilentElement.accessibilityLabel = "some text i want read aloud"

iPhone 8
iOS 14.5.1
XCode 12.5

4b0
  • 21,981
  • 30
  • 95
  • 142
Mark
  • 765
  • 8
  • 12
0

This worked for me at the time I had asked this question (a workaround, not proper solution).

I handled it by forced selection of another accessibility element. For example, after making selection from TableView/CollectionView, I'm supposed to navigate to new UI. What I'm doing is that I forcefully select left bar button item of navigation bar of new UI right after navigation is completed. Selection is made using UIAccessibilityPostNotification. This way, it starts reading newly selected item. Please see this link for selection

Maverick
  • 3,209
  • 1
  • 34
  • 40