我的应用程序中有3个按钮,当开启语音并且用户向右滑动时,选择下一个按钮。
注意 - 按钮辅助功能焦点与按下的按钮不同。
提问的理由 - 我希望应用宣布" AAA"当选择按钮1时" BBB"当按下按钮1时。
问题
答案 0 :(得分:3)
View(在本例中为按钮)需要实现协议UIAccessibilityFocus
- (void)accessibilityElementDidBecomeFocused
- (void)accessibilityElementDidLoseFocus
- (BOOL)accessibilityElementIsFocused
答案 1 :(得分:0)
以下是一些ObjectiveC代码行来执行您想要执行的操作:
// Create button
UIButton *b = [[UIButton alloc] init];
// Set it's title
[b setTitle:@"AAA" forState:UIControlStateNormal];
// Set the label, i.e. it's name
[b setAccessibilityLabel:NSLocalizedString(@"AAA", @"")];
// Set button action description
[b setAccessibilityHint:NSLocalizedString(@"AAA button action description", @"")];
// Ad the button target, it's action
[b addTarget:self action:@selector(yourMethod:) forControlEvents:UIControlEventTouchUpInside];
// Add an observer
[b addObserver:self forKeyPath:@"state" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
// Implement this method in your controller
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
if (object == self.b && [keyPath isEqualToString:@"state"]) {
if (self.b.state == UIControlStateSelected) {
// DO WHAT YOU WANT TO DO ON SELECTION
}
}
}
查看Apple accessibility Guide了解更多信息。