辅助功能 - UIPickerView 作为 inputView
Accessibility - UIPickerView as inputView
我正在使用 UIPickerView
作为 UITextField
的 inputView。
self.pickerView = [[UIPickerView alloc]initWithFrame:CGRectZero];
self.pickerView.dataSource = self.datasource;
self.pickerView.delegate = self.delegate;
//additional setups
self.textField.inputView = self.pickerView;
一切正常,但是当我激活画外音并开始循环播放 itens 时,画外音开始发出错误的通知。
我做了一些研究,我在 github 上找到了一个有同样问题的人的回购协议,但我找不到任何解决方案。
我找到了这个案例的解决方法。在 pickerView(_:didSelectRow:inComponent:)
方法中,我使用 UIAccessibilityPostNotification
和 UIAccessibilityAnnouncementNotification
,传递选择的项目,强制画外音发出正确的通知。
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);
}
}
我正在使用 UIPickerView
作为 UITextField
的 inputView。
self.pickerView = [[UIPickerView alloc]initWithFrame:CGRectZero];
self.pickerView.dataSource = self.datasource;
self.pickerView.delegate = self.delegate;
//additional setups
self.textField.inputView = self.pickerView;
一切正常,但是当我激活画外音并开始循环播放 itens 时,画外音开始发出错误的通知。
我做了一些研究,我在 github 上找到了一个有同样问题的人的回购协议,但我找不到任何解决方案。
我找到了这个案例的解决方法。在 pickerView(_:didSelectRow:inComponent:)
方法中,我使用 UIAccessibilityPostNotification
和 UIAccessibilityAnnouncementNotification
,传递选择的项目,强制画外音发出正确的通知。
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);
}
}