gpt4 book ai didi

objective-c - 自定义 UIView 在画外音时不显示辅助功能

转载 作者:可可西里 更新时间:2023-11-01 04:26:41 24 4
gpt4 key购买 nike

我正试图通过使用 openGL View 获得发言权,特别是来自 cocos2d 框架。

根据 Apple 辅助功能指南,我遵循了以下部分:Make the Contents of Custom Container Views Accessible

我已经对 View (cocos2d 用户使用 CCGLView)进行了子类化,这是一个 UIView,以实现非正式的 UIAccessibilityContainer 协议(protocol)。

我的子类 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 数组。但是,当我触摸屏幕时,画外音控件没有出现。关于我遗漏或做错了什么的任何想法?

其他信息:

我正在使用 Storyboard并将 CCGLView 添加到 Storyboard中的 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];

有一段时间我怀疑是因为我添加了 subview 导致它不显示,但我也尝试以相同的方式在 Storyboard 中子类化 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;

最佳答案

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

关于objective-c - 自定义 UIView 在画外音时不显示辅助功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13462046/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com