5

我正在尝试使用openGL视图,特别是来自cocos2d框架的语音。自定义UIView不显示语音上的辅助功能

从Apple辅助引导我跟着本节:Make the Contents of Custom Container Views Accessible

我子类(对cocos2d的人CCGLView)的观点,这是一个UIView,实施正规UIAccessibilityContainer协议。

在我的子类的UIView UIAccessibilityContainer实现:

-(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]; 
} 

此代码获取调用和-(NSArray *)acessibilityElements将返回UIAccessibilityElements的数组。但是,当我触摸屏幕时,控制声音不会显示出来。关于我失踪或做错的任何想法?

其他信息:

我使用的是故事板,并添加CCGLView到了UIView的故事板。 _director.view是我分类的CCGLView。

// 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]; 

有一段时间我怀疑是因为我添加子视图,这是导致它没有露面,但我也试图以同样的方式继承了UIView在故事板,但它也不能正常工作。

这也是我如何在数组中创建每个UIAccessibilityElement。

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; 

回答

6

找到了一个现在可以使用的解决方案,以防万一有人遇到这个问题。 -(id)accessibilityElementAtIndex:(NSInteger)index正在返回一个合适的UIAccessibilityElement,但它看起来没有被任何Accessibility API使用它保留。我做了一个强大的NSArray属性来保存UIAccessibilityElements,现在它工作正常。

+0

现在几个小时的时间我一直在坚持 - 谢谢! –