VoiceOver 和异步 UITableView

VoiceOver and asynchronous UITableView

在我的应用程序中,我有一个带有异步数据加载的 UITableView:当加载视图控制器时,我显示一个模态 activity 微调器并启动 HTTP 请求。完成后,我隐藏微调器并在我的 table 视图上执行 reloadData()。我还将 return response?.count ?? 0 作为行数,以确保列表在数据尚未准备好时最初为空。

它就像一个魅力,但我对 VoiceOver 有一个问题:打开视图控制器时,VoiceOver 进入 table 并显示 "empty list"。加载数据后,它会转到 table.

的最后一个元素

这种行为不是很理想:我希望 VoiceOver 在 table 为空时不要聚焦它(它不需要聚焦模态微调器,因为我们在加载时已经有声音)然后加载后转到第一个元素。

我该怎么做?

您想将加载覆盖屏幕设置为模态视图。模态表示视图背后的内容不可操作(或无法通过 VoiceOver 聚焦)。

//Instantiate a view controller with your loading spinner.
_modalDialogViewController = [[UIStoryboard storyboardWithName:@"ModalDialog" bundle:[NSBundle mainBundle]]
                       instantiateViewControllerWithIdentifier:@"AccessibleSpinnerModal"];

//Make this view controller modal, meaning only things on this screen will be actionable/focusable.
_modalDialogViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;

您可能还需要使用这些样式中的任何一种形式的辅助功能通知。

//Announce that content is loading directly 
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, "Stuff is laoding");

或者

//Shift focus to the view in your modal that is sharing the status of the loading content.
UIAccessibilityPostNotification(UIAccessibilityLayoutChanged, spinnerView);

这将使焦点移动到该视图。