我是一名IOS初学者,试图为UIButton启用辅助功能 . 出于传统目的,我们仍在使用Objective-C编写IOS应用程序 . 我的按钮代码如下:
-(UIButton*) initializeDoneButton {
UIButton *doneButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 10)];
[doneButton setTitle:@"Done" forState:UIControlStateNormal];
[doneButton addTarget:self action:@selector(finishTheProcess:)
forControlEvents:UIControlEventTouchUpInside];
[doneButton setIsAccessibilityElement:YES];
[doneButton setAccessibilityLabel:@"Done Button"];
[doneButton setAccessibilityHint:@"Tap button to complete the process"];
return doneButton;
}
我的回调函数
- (void) finishTheProcess:(UIButton *)sender {
// Code here to finish the process.
}
我看到声音只是轻轻一声,而不是双击 . 理想情况下,第一次点击应该在声音上宣布标签“完成”的 Headers . 第二次点击应该执行动作回调函数 . 这甚至可能吗?
我已阅读Apple关于辅助功能的教程,但我无法弄清楚如何为UIButton启用辅助功能 .
Update
这是根据我的名字提交的错误报告
Actual Result : Voice Over announces only tap instead of double tap for “Done”.
Expected Result : Voice Over should announce as double tap.
2 回答
tl; dr - 修改
accessibilityHint
来说"double tap"iOS上的辅助功能元素具有许多可以公布的Voice Over特征 . 首先要了解可访问性焦点的功能 . 为了区分打算点击屏幕上的按钮的用户与想要了解有关该元素的更多信息的用户,Apple实现了一个可访问性焦点,基本上就像将鼠标悬停在浏览器上的网页元素上以获取更多信息 . 当用户在辅助功能元素上点击一次或在元素之间向左/向右滑动时,将激活此焦点 .
轻触辅助功能元素后,Voice Over会发布有助于用户理解辅助功能焦点元素的信息 . 这些公告可以通过辅助功能进行定制,并按以下顺序说明 .
doneButton.accessibilityLabel = "Done";
doneButton.accessibilityTraits = UIAccessibilityTraitButton;
*对于UIButton类的对象,此特征将默认为UIAccessibilityTraitButton
doneButton.accessibilityHint = "Double tap the button to complete the process.";
*一旦UIAccessibilityTrait被宣布,许多可访问性用户将知道双击按下按钮
可以设置其他可访问性特征,但这些特性将涵盖您需要的大多数功能 . 您的代码实际上非常接近于运营 . 你真正需要做的就是修改
accessibilityHint
来说出你想要的声音 .在
initializeDoneButton
方法中添加doneButton.accessibilityTraits = UIAccessibilityTraitButton;
.