I'm using a UIPickerView
as an inputView of UITextField
.
self.pickerView = [[UIPickerView alloc]initWithFrame:CGRectZero];
self.pickerView.dataSource = self.datasource;
self.pickerView.delegate = self.delegate;
//additional setups
self.textField.inputView = self.pickerView;
Everything works fine, but when i active voiceover and start to cycling through the itens, the voiceover start to make incorrect announcement.
I did some research and I found a repo on github with someone that have the same problem, but i couldn't find any solution.
I find a workaround for this case. On the pickerView(_:didSelectRow:inComponent:)
method, i use UIAccessibilityPostNotification
with UIAccessibilityAnnouncementNotification
, passing the item that was selected, forcing the voiceover to make the correct announcement.
Objective-C:
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
if(UIAccessibilityIsVoiceOverRunning()){
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, self.items[row]);
}
}
Swift:
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if(UIAccessibility.isVoiceOverRunning){
UIAccessibility.post(notification: UIAccessibility.Notification.announcement, argument: self.items);
}
}