简体   繁体   中英

Disable accessibility (VoiceOver) on a MKMapView

What I want to do is to disable accessibility on a MKMapView . Actually VoiceOver reads all the element on the map: roads, POI ecc. ecc.

So I tried this

[map setIsAccessibilityElement:NO]

but don't work...how to achieve this? I am missing something?

Yes, indeed, you are missing something. This isn't how the "isAccessibilityElemnt" property works. By setting your view as not an accessibility element, you're only telling VoiceOver to ignore THAT view, not that view and all of its children.

What you want to do, is write a recursive function to set the "isAccessibilityElement" property to no for all subviews. I got caught in VA in the epic snowstorm, without my mac. I just started playing around with Swift, but don't have a complier, so this is Swift (ish) pseudo code.

func setA11yElementRecursive(view: UIView, toThis: bool) {
    view.isAccessibilityElement = toThis

    for (View v : view.subviews) {
        setA11yElementRecursive(v, toThis)
    }
}

DISCLAIMER: The implications of this however, are that every element you set as not an accessibility element, VoiceOver (and any other AT) will assume that your view is not important for accessibility. Meaning it will be completely ignored! Anyone using VoiceOver on your app (or at least on this view) will assume that nothing is there. Your app will appear as a blank canvas. Partially sighted users who rely on VoiceOver to read the small print on your labels will swipe over elements on your UI and it will appear to them as no element is there. They will be confused as to why they see a label there, but can't have it read out to them. There are very few circumstances in which setting this property to NO on items that present information is appropriate. Even if you believe that blind people shouldn't be using your app or this particular feature of your app.

Your 'MKMapView' may be seen as a container whose elements should not be seen by VoiceOver thanks to the `accessibilityElementsHidden' property.

@IBOutlet weak var map: MKMapView!

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    map.accessibilityElementsHidden = true
}

Using this property as shown in the code snippet above disables VoiceOver on a MKMapView .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM