辅助功能-UIPickerView作为inputView

问题描述 投票:0回答:1

我正在使用UIPickerView作为UITextField的inputView。

self.pickerView = [[UIPickerView alloc]initWithFrame:CGRectZero];

self.pickerView.dataSource = self.datasource;
self.pickerView.delegate = self.delegate;

//adicional setups

self.textField.inputView = self.pickerView;

一切正常,但是当我激活画外音并开始循环浏览声音时,画外音开始发出错误的提示。

我进行了一些研究,发现与一个有相同问题的人在github上有一个存储库,但是我找不到任何解决方案。

ios uipickerview voiceover
1个回答
0
投票

我找到了这种情况的解决方法。在pickerView(_:didSelectRow:inComponent:)方法上,我使用UIAccessibilityPostNotification传递所选项目,从而强制画外音做出正确的通知。

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);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.