objective-c - 如何正确地将 WKWebView 添加到 AccessibilityContainer 中的可访问性元素?
问题描述
我有一个使用 AccessibilityContainer 和 AccessibilityElements 的自定义配置的辅助功能树。现在我想在 AccessibilityContainers 之一下添加一个 WKWebView 作为 AccessibilityElements。
一切正常,除非我想直接选择一个可访问性元素(在 Web 视图中移动手指以查找元素)。
我用已弃用的 UIWebView 替换了 WKWebView,它运行良好。
如果我没有自定义配置树,WKWebView 的可访问性也可以完美运行。
我创建了一个示例代码来重现该问题,我在此代码中所做的操作在实际应用程序中可能没有意义,但它复制了我在项目中的设置。
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 100)];
label.backgroundColor = [UIColor yellowColor];
label.textColor = [UIColor blueColor];
label.text = @"Here is some text";
CGRect webViewRect = CGRectMake(0, 100, self.view.bounds.size.width, self.view.bounds.size.height-100);
WKWebView *webview = [[WKWebView alloc] initWithFrame:webViewRect];
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://google.com"]]];
webview.accessibilityFrame = webViewRect;
[self.view addSubview:label];
[self.view addSubview:webview];
self.view.accessibilityElements = @[label, webview];
// Do any additional setup after loading the view, typically from a nib.
}
我希望辅助功能检查器可以选择 WKWebView 中的元素,但在这种情况下它们不是。
解决方案
推荐阅读
- html - @page margin 导致在打印时隐藏固定位置的页眉和页脚
- ffmpeg - 为什么ffmpeg生成的psnr值是inf?
- module - 模块之间的USES关系是传递的吗?
- vue.js - Vitepress 自定义主题,不同页面的多种布局
- ios - 无法使用 Swift 5.3.0 为 iOS 模拟器构建 React Native 应用程序
- windows - 在 ec2 windows 中运行的进程
- python - 在 VS Code 中创建 python 文件
- java - 不好的做法或不赞成使用逗号分隔大小写?切换 case 语句 Java
- reactjs - React - 方法不更新 DOM
- typescript - 为什么打字稿将未知范围缩小到永远不会在可到达的条件块内?