Reputation: 119
I am creating view based application, where i will be going to next view, via addSubview
method.
The problem is, when I turn the feature of VoiceOver ON, and addsubviews, it takes the accessory labels from previous views. That is , if I click on view at the rect, where there is label in previous view, then also, VoiceOver will detect it as accessibility label and start reading that label.
But, If I use, navigation controller to go to next view controller, I don't get any problem.
Can anyone please tell me, if apple itself has supported VoiceOver facility only for navigation based application, or there is some other solution for VoiceOver in view based applications ?
PS I have tried the same on some demo apps also, but same results.
So, when in current view I am adding a subview which contains buttons, accessibility reads the labels behind the subview as well. I want the accessibility to read buttons on added view, and rest of the viewable part of the previous view only(and not the labels got hidden behind added view). can someone tell, if it is a bug of voiceover in iPhone, that by default, it reads parentView's labels also, on addsubview ?
Upvotes: 6
Views: 4784
Reputation: 61
You can set the accessibilityViewIsModal property of the view to YES.
@property (nonatomic) BOOL accessibilityViewIsModal NS_AVAILABLE_IOS(5_0);
Informs whether the receiving view should be considered modal by accessibility. If YES, then elements outside this view will be ignored. Only elements inside this view will be exposed. default == NO
so whatever view you are adding, set it's accessibilityViewIsModal to YES / true.
view.accessibilityViewIsModal = YES
Upvotes: 6
Reputation: 132
I had the same problem as you, and I spent some time to solve this. When you add view B over view A, you do not hidden view A. The view continues there, and as expected by voiceOver, it will read that view/label.
You can use the Debug View that Xcode provides for you, to see this kind of problem. I wrote a example to demostre you how voiceOver see your labels.
When you use addSubview, you hierarchy of views are like that:
So in this case, the container view, with Hello Stack! label is over the Hello World label. As a user you cannot see the label Hello World. However voiceOver can see that view.
All right, now that the problem is known, the solution is: whenever you want to add a view over another one, first hidden the previous view. Then use Debug View of xcode to see how your views are.
I fix that to show you how to correct the error I demonstrated:
In Code:
Debug view:
If you observer, I had added a view container between the labels, but this view is just to improve the vision of the hierarchy.
Upvotes: 3
Reputation: 955
Use this screen changed notification
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);
if you need to focus a specific object/view then pass those at the place of nil.
Upvotes: 4
Reputation: 45598
If a view is in the view hierarchy, even if it is obscured by another view on top of it, VoiceOver will detect that.
You should not be moving to another screen of content by just adding a new view on top of the previous one. Each screen of your app should be a UIViewController
, not just a plain UIView
. This gives you many advantages, one of which is that a view controller can automatically unload its view when it is off screen and there is a memory warning.
To manage transitions between screens in your app, you should use a container controller like a navigation controller (or your own custom one). You can disable the navigation bar and transition effects if you like, and just use it to manage your stack of views. When you push a new view controller onto the stack, the previous one will be removed and your problem goes away.
So you should seriously reconsider the way you are managing your screens and views. UIViewController
inside some sort of container is the way to go. At the very least, you should be removing the old view when you add a new one to the screen.
Upvotes: 9