Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent VoiceOver revealing views that are beneath a larger transparent view

Summary: I want to replicate the accessibility behaviour of a UIAlertView, where the background view is still visible but VoiceOver does not interact with it.

Detail: I have implemented accessibility for an iPhone app, but have one problem remaining. In some cases I display a large view on top of all others (partially transparent, covering most of the original view) containing labels and a close button. i.e. basically a custom popup/alert view. The problem is, VoiceOver continues to reveal the views/controls underneath it.

One method to prevent the hidden views from being revealed by VoiceOver is to set the whole custom view background to be accessible. However, this isn't really what we want as this containing view shouldn't really be interacted with by the user, only its subviews (labels/buttons) should.

like image 686
Chris Miles Avatar asked Feb 15 '11 01:02

Chris Miles


2 Answers

I think you should use this on your top laying view:

Objective-C

- (BOOL)accessibilityViewIsModal {
    return YES;
}

Swift

accessibilityViewIsModal = true

This makes every element of the View Controller that is hidden unaccessible.

An implementation could be to set it to true when you show the view and set it to false when you dismiss that view.

More info

Note: Requires iOS5 and up

like image 169
JaySH Avatar answered Nov 15 '22 13:11

JaySH


Swift 4

In swift try this: Before your view is presented setup your viewController’s view like this:

yourViewController.view.accessibilityViewIsModal = true

Also try setting the self.view.accessibilityViewIsModal to true in viewWillAppear

override func viewWillAppear(_ animated: Bool) {
   super.viewWillAppear(animated)
   view.accessibilityViewIsModal = true
}

It also might help if you send a screen chances notification when your modal or pop up view is appearing by adding this to the viewWillAppear:

UIAccessibility.post(notification: .screenChanged, argument: nil)
like image 36
Ramin Avatar answered Nov 15 '22 13:11

Ramin