[英]Accessibility - UIPickerView as inputView
I'm using a UIPickerView
as an inputView of UITextField
.我使用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;
Everything works fine, but when i active voiceover and start to cycling through the itens, the voiceover start to make incorrect announcement.一切正常,但是当我激活画外音并开始在 itens 中循环时,画外音开始发出不正确的公告。
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.我做了一些研究,我在github上找到了一个有同样问题的人的 repo,但我找不到任何解决方案。
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.在pickerView(_:didSelectRow:inComponent:)
方法上,我将UIAccessibilityPostNotification
与UIAccessibilityAnnouncementNotification
一起使用,传递选择的项目,强制画外音发出正确的通知。
Objective-C:目标-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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.