我为两个基于框架的可访问性元素创建了一个容器,这些元素是在自定义 uiview 中使用核心图形绘制的。
我希望这两个元素(在本例中为两个光标)响应一根手指的上下滑动,所以我使用 trait UIAccessibilityTraitAdjustable
。
我已经实现了 Apple 文档中描述的协议。我可以选择这两个元素,但单指滚动似乎没有调用accessibilityIncrement
and accessibilityDecrement
。有什么我错过的吗?
-(NSArray *)accessibleElements
{
if (_accessibleElements != nil) {
return _accessibleElements;
}
_accessibleElements = [[NSMutableArray alloc] init];
//add left cursor
UIAccessibilityElement *lcursorEl = [[UIAccessibilityElement alloc]
initWithAccessibilityContainer:self];
lcursorEl.accessibilityFrame = [self convertRect:_lcursorFrame
toView:nil];
lcursorEl.accessibilityLabel = NSLocalizedString(@"Left Cursor", nil);
lcursorEl.accessibilityTraits = UIAccessibilityTraitAdjustable;
[_accessibleElements addObject:lcursorEl];
//add right cursor
UIAccessibilityElement *rcursorEl = [[UIAccessibilityElement alloc]
initWithAccessibilityContainer:self];
rcursorEl.accessibilityFrame = [self convertRect:_rcursorFrame
toView:nil];
rcursorEl.accessibilityLabel = NSLocalizedString(@"Right Cursor", nil);
//rcursorEl.accessibilityTraits = UIAccessibilityTraitAdjustable ;
[_accessibleElements addObject:rcursorEl];
return _accessibleElements;
}
#pragma mark accessible elements protocol methods
- (NSInteger)accessibilityElementCount
{
return [[self accessibleElements] count];
}
- (id)accessibilityElementAtIndex:(NSInteger)index
{
return [[self accessibleElements] objectAtIndex:index];
}
- (NSInteger)indexOfAccessibilityElement:(id)element
{
return [[self accessibleElements] indexOfObject:element];
}
- (BOOL)isAccessibilityElement
{
return NO;
}
-(void)accessibilityIncrement
{
NSLog(@"Adjusting Inc");
}
-(void)accessibilityDecrement
{
NSLog(@"Adjusting dec");
}