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

現在幾個小時的時間我一直在堅持 - 謝謝! –