首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIAccessibility没有选择正确的元素

UIAccessibility没有选择正确的元素
EN

Stack Overflow用户
提问于 2016-09-01 19:53:48
回答 1查看 235关注 0票数 0

我的应用程序中有几个UIWindows。一些UIWindows具有非常高的窗口级别。即

代码语言:javascript
复制
window.windowLevel = currentWindowLevel+1;

由于某些原因,当打开辅助功能支持时,系统坚持读取位于较低级别窗口中的视图的辅助功能标签,即使在视图甚至不可见的情况下。

这个最小的例子举例说明了这种行为。

打开辅助功能支持后,尝试按红色窗口中的标签。系统将从下面的表视图中读出文本

代码语言:javascript
复制
@interface ViewController () <UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableview;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableview.dataSource = self;
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        UIWindow *w = [[UIWindow alloc] initWithFrame:self.view.bounds];
        w.windowLevel = self.view.window.windowLevel + 1;
        w.backgroundColor = [UIColor redColor];
        w.hidden = NO;
        w.isAccessibilityElement = YES;
        UILabel *l = [[UILabel alloc] init];
        l.text = @"KUKUKUKUKUKUKUKLU";
        [l sizeToFit];
        l.frame = CGRectOffset(l.frame, 40, 100);
        [w addSubview:l];
        w.accessibilityLabel = @"Read this outloud instead";
        static id window;
        window = w;
    });

    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 100;
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.text = @"Test";
    return cell;
}

@end
EN

回答 1

Stack Overflow用户

发布于 2016-09-02 01:00:10

解决方案是设置属性

代码语言:javascript
复制
Window.accessibilityViewIsModal = YES;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39270878

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档