gpt4 book ai didi

ios - 将 subview 添加到自定义 viewForHeaderInSection 会破坏 VoiceOver 导航

转载 作者:可可西里 更新时间:2023-11-01 03:59:42 24 4
gpt4 key购买 nike

我有一个 UITableViewController,我正在尝试自定义部分标题,使其看起来更像纯文本。我发现当我将 subview 添加到自定义 headerView(详见下文)时,它会破坏 VoiceOver 标题导航。

例如:假设我有一个包含三个标题的表格:Header1、Header2、Header3。

如果没有 viewForHeaderInSection 方法的自定义实现,我可以将画外音转子切换为按标题导航,一切都按预期进行。

当我按以下方式实现 viewForHeaderInSection 方法时,我可以从 Header1 移动到 Header2 再到 Header3 并返回到 Header2,但是画外音会丢失所有 header (说“找不到 header ”)。

当我将 headerLabel 作为 subview 添加到 headerView 时,我发现问题开始了。我尝试将 headerLabel 设置为隐藏的辅助功能元素,这样画外音就不会拾取它,但问题仍然存在。

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{

UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,tableView.frame.size.width,30)];

UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, headerView.frame.size.width-120.0, headerView.frame.size.height)];

headerLabel.textAlignment = UITextAlignmentLeft;
headerLabel.font = [UIFont boldSystemFontOfSize:22];
headerLabel.text = [headersArray objectAtIndex:section];
headerLabel.backgroundColor = [UIColor clearColor];

[headerView addSubview:headerLabel];

return headerView;

}

如果知道 VoiceOver 的 react 为何如此,我们将不胜感激。

谢谢。

最佳答案

这不太可能是原始问题的答案,但我只是解决了一个类似的问题。

我为部分标题定制了 UIView,并将这些内容保存在一个数组中,并偶尔重复使用它们。这完全混淆了 VoiceOvery,前进或后退并不总能按预期选择上一个或下一个单元格。

但是,当我更改为每次调用 tableView:viewForHeaderInSection: 时都创建一个新的 UIView 时,VoiceOver 的这种导航困惑就停止了,并且一切正常。我的标题 View 是可访问的 (isAccessibleElement) 并且有一个标签集。

关于ios - 将 subview 添加到自定义 viewForHeaderInSection 会破坏 VoiceOver 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9070598/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com