【发布时间】:2014-12-01 23:08:53
【问题描述】:
我有一个带有自定义标题的 UITableView(即我自己创建了 UIView)。我需要调整视图子视图之一的accessibilityFrame,但我不知道如何适当地设置框架的坐标——它们需要相对于窗口,但我不确定如何完成那个。
我的代码看起来像
- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger) section
{
CGRect bounds = CGRectMake(0, 0, [tableView frame].size.width, 48);
UIView *header = [[UIView alloc] initWithFrame:bounds];
UILabel *labelOne = [[UILabel alloc] initWithFrame:
CGRectMake(0, 0, bounds.size.width - 80, 18)];
UILabel *labelTwo = [[UILabel alloc] initWithFrame:
CGRectMake(0, 20, bounds.size.width - 80, 18)];
CGRect frameOne = [labelOne frame];
CGRect frameTwo = [labelTwo frame];
[labelTwo setIsAccessibilityElement:NO];
[labelOne setAccessibilityFrame:CGRectUnion(frameOne, frameTwo)];
// ...
return header;
}
我有两个 UILabel,我想将它们合并为一个以用于 VoiceOver。我通过忽略第二个标签并扩展第一个标签的框架以覆盖第二个标签的区域来实现这一点。 (第二个标签就在第一个标签的下方。)问题在于获取帧。如果我使用如上所示的代码,可访问性框架的大小是正确的,但它的位置就像 UITableView 的标题位于屏幕的左上角一样。我试着修改代码说
CGRect frameOne = [header convertRect:[labelOne frame] toView:nil];
CGRect frameTwo = [header convertRect:[labelTwo frame] toView:nil];
但同样的事情发生了。后一段代码不应该将 UILabel 的框架转换为相对于窗口的坐标吗?
我认为问题可能是当 UIView 被创建时,它不知道它在屏幕上的位置(并且作为 UITableView 的一部分,它可能会在整个地方滚动)。是否有必要将accessibilityFrame实现为每次调用时检查UIView位置的消息?
【问题讨论】:
标签: ios accessibility