简体   繁体   中英

Accessibility - UIPickerView as inputView

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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM