Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom UIView Not Showing Accessibility on Voice Over

I'm trying to get voice over working with an openGL view, specifically from the cocos2d framework.

From the Apple Accessibility guide I followed this section: Make the Contents of Custom Container Views Accessible

I've subclassed the view (CCGLView for cocos2d people), which is a UIView, to implement the informal UIAccessibilityContainer protocol.

UIAccessibilityContainer implementation in my subclassed UIView:

-(NSArray *)accessibilityElements{
return [self.delegate accessibleElements];
}

-(BOOL)isAccessibilityElement{
return NO;
}
-(NSInteger)accessibilityElementCount{
return [self accessibilityElements].count;
}
-(NSInteger)indexOfAccessibilityElement:(id)element{
return [[self accessibilityElements] indexOfObject:element];
}
-(id)accessibilityElementAtIndex:(NSInteger)index{
return [[self accessibilityElements] objectAtIndex:index];
}

This code is getting called and -(NSArray *)acessibilityElements is returning an array of UIAccessibilityElements. However the voice over controls are not showing up when I touch the screen. Any ideas on what I'm missing or doing wrong?

Other Information:

I'm using a storyboard and adding the CCGLView to the UIView in the storyboard. The _director.view is the CCGLView that I subclassed.

 // Add the director as a child view controller.
[self addChildViewController:_director];

// Add the director's OpenGL view, and send it to the back of the view hierarchy so we can place UIKit elements on top of it.
[self.view addSubview:_director.view];
[self.view sendSubviewToBack:_director.view];

For a while I suspected that because I added the subview that this was causing it not to show up, but I also tried subclassing the UIView in the storyboard the same way but it was also not working.

Also this is how I am creating each UIAccessibilityElement in the array.

UIAccessibilityElement *elm = [[UIAccessibilityElement alloc] initWithAccessibilityContainer:view];
    elm.accessibilityFrame = f;
    elm.accessibilityLabel = t.letter;
    elm.isAccessibilityElement = YES;
    elm.accessibilityHint = @"Button";
    elm.accessibilityValue = t.letter;
    elm.accessibilityTraits = UIAccessibilityTraitButton;
like image 970
tassinari Avatar asked Nov 19 '12 20:11

tassinari


Video Answer


1 Answers

Found a solution that is working now, in case anyone has this problem. -(id)accessibilityElementAtIndex:(NSInteger)index was returning a properUIAccessibilityElement but it looks like it wasn't getting retained by whatever Accessibility API is using it. I made a strong NSArray property to hold the UIAccessibilityElements and now it is working fine.

like image 132
tassinari Avatar answered Oct 12 '22 22:10

tassinari