5

我正在尝试使用 openGL 视图进行配音,特别是来自 cocos2d 框架。

从Apple Accessibility guide我遵循了这个部分:使自定义容器视图的内容可访问

我已经将视图(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;
4

1 回答 1

8

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

于 2012-12-05T15:56:10.443 回答