我用兩個拇指創建了自定義範圍UISlider。但是在VoiceOver模式下,我無法上下滑動以調整拇指。自定義UISlider上的輔助功能
UIAccessibilityElement *minElement = [[UIAccessibilityElement alloc] initWithAccessibilityContainer:self];
minElement.accessibilityFrame = [self convertRect:currentThumbRect
toView:nil];
minElement.accessibilityLabel = NSLocalizedString(@"Minimum", nil);
minElement.accessibilityTraits = UIAccessibilityTraitAdjustable;
[_accessibleElements addObject:minElement];
UIAccessibilityElement *maxElement = [[UIAccessibilityElement alloc]
initWithAccessibilityContainer:self];
maxElement.accessibilityFrame = [self convertRect:currentUpperThumbRect
toView:nil];
maxElement.accessibilityLabel = NSLocalizedString(@"Maximum", nil);
maxElement.accessibilityTraits = UIAccessibilityTraitAdjustable;
[_accessibleElements addObject:maxElement]
我在上面添加了代碼,以便VoiceOver可以單獨識別兩個拇指,但我無法調整拇指。任何想法都可以在VoiceOver中調整大拇指。
問題就迎刃而解了:
我用 'UIAccessibilityCustomAction' 在自定義行爲增加。而不是上下滑動以調整值,在自定義行爲中上下滑動可用於選擇動作並雙擊執行。
UIAccessibilityElement *minElement = [[UIAccessibilityElement alloc] initWithAccessibilityContainer:self];
minElement.accessibilityLabel = NSLocalizedString(@"Minimum", nil);
UIAccessibilityCustomAction *increaseMinAction = [[UIAccessibilityCustomAction alloc] initWithName:NSLocalizedString(@"Increase minimum", @"action to increase min")
target:self selector:@selector(accessibilityMinIncrement)];
UIAccessibilityCustomAction *decreaseMinAction = [[UIAccessibilityCustomAction alloc] initWithName:NSLocalizedString(@"Decrease minimum", @"action to decrease min")
target:self selector:@selector(accessibilityMinDecrement)];
minElement.accessibilityCustomActions = @[increaseMinAction, decreaseMinAction];
[_accessibleElements addObject:minElement];