添加可访问性自定义滑块 iOS

add accessibility custom slider iOS

我有一个自定义滑块,它根据 super.beginTrackingWithTouchsuper.continueTrackingWithTouch 更改值。它遵循二次路径。

希望使自定义滑块易于访问。有什么想法吗?

我正在考虑添加一个标准 iOS 滑块,添加 accessibilityLabel,并将这些值传递给自定义滑块。无法使标准滑块正常工作但对用户不可见。

如果可访问,你的意思是画外音,你可以执行以下操作,假装 mySlider 是你的滑块控件的名称:

    [mySlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];

- (IBAction)sliderValueChanged:(UISlider *)sender {
    NSString *valueToAnnounce=[NSString stringWithFormat:@"slider value = %f", sender.value];
    UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, valueToAnnounce);
}

此博客多次帮助我解决画外音问题: http://www.podfeet.com/blog/tutorials-5/build-accessible-ios-apps/

It's generally best practice to extend a standard control to perform the special behavior you need. As author of a completely custom control, you're responsible for more of its accessibility.

Experiment with a UISlider using VoiceOver on your device. See how it behaves. You want to maintain as much of this experience as possible as you implement your own control. You can use Accessibility Inspector in Simulator to explore system controls' accessibility configurations.

The following steps are almost certainly relevant:

  1. Override or set - (BOOL)isAccessibilityElement to return YES.
  2. Override or set - (CGRect)accessibilityFrame to return an appropriate rectangle in screen coordinates.
  3. Override or set - (UIAccessibilityTraits)accessibilityTraits to include UIAccessibilityTraitAdjustable.
  4. Override - (NSString *)accessibilityValue to describe the current value of your control.
  5. Implement - (void)accessibilityIncrement and - (void)accessibilityDecrement to perform value changes requested by assistive clients such as VoiceOver.

Beyond the steps above, I can't say what's required for your specific control without more details. If you get stuck, review the Accessibility Programming Guide, UIAccessibility Protocol documentation, and UIAction protocol documentation, and return to Whosebug with any questions that remain.

Best luck and thank you for giving this the attention it deserves.