问题描述
当 VoiceOver 启用时,无论我们滑动到哪一行,UIPickerView 的画外音总是说“#Item 1 of #TotalNumberOfItems”。 以编程方式,所有元素都使用正确的选定索引进行更新,但 VoiceOver 始终显示“#TotalNumberOfItems 的#Item 1”
让我知道是否有人在 PickerView 中遇到过这个问题?
一些观察:
- 如果我们离开应用一段时间然后滑动,索引会正确发音一次,然后同样的问题仍然存在
- 如果我们在滑动后点击选择器行,索引会正确发音
- 每次我们滑动行时,didSelect 都会被调用 2 次。
- DatePicker 工作正常
- 默认提醒应用有一些 PickerViews,画外音按预期工作。 (虽然发现上下滚动时索引细节不对)
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.normalPicker.backgroundColor = [UIColor blackColor];
self.categories = [[NSMutableArray alloc] initWithObjects:@"Apple",@"Bat",@"Cat",@"Dog",@"Elephant",@"Fish",@"Goat",@"Hen",nil];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return self.categories.count;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSLog(@"DidSelect: Row = %@",self.categories[row]);
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *label = nil;
if (view == nil) {
label = [UILabel new];
label.adjustsFontSizetoFitWidth = NO;
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor redColor];
} else {
label = (UILabel *) view;
}
Nsstring *text = self.categories[row];
label.text = text;
return label;
}
@end
解决方法
找到了相同的解决方法。发布包含附加到实际字符串的索引的公告。
-(void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{...
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification,voiceOverText);
}