UIAccessibility没有选择正确的元素

时间:2016-09-01 11:53:48

标签: uikit uiwindow voiceover uiaccessibility

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

window.windowLevel = currentWindowLevel+1;

出于某种原因,在启用辅助功能支持时,系统会坚持读取位于较低级别窗口中的视图的辅助功能标签,即使在视图甚至不可见的情况下也是如此。

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

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

@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

1 个答案:

答案 0 :(得分:1)

解决方法是设置属性

Window.accessibilityViewIsModal = YES;