I have a UITableView with a custom header (i.e. I create a UIView myself). I need to configure the accessibilityFrame interface of one of the view subzones, but I cannot figure out how to set the frame coordinates correctly - they should be relative to the window, but I'm not sure how to do this.
My code looks like
- (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)];
I have two UILabels that I want to merge into one for VoiceOver purposes. I do this by ignoring the second label and expanding the frame of the first label to cover the area of ββthe second label. (The second label is immediately lower than the first.) The problem is getting frames. If I use the code as shown above, the accessibility frame is the correct size, but it is positioned as if the UITableViews header was in the upper left corner of the screen. I tried changing the code to say
CGRect frameOne = [header convertRect:[labelOne frame] toView:nil]; CGRect frameTwo = [header convertRect:[labelTwo frame] toView:nil];
but the same thing happened. Should this last piece of code convert UILabels frames to relative window coordinates?
I thought that maybe the problem is that when the UIView is created, it does not know where it will be positioned on the screen (and as part of the UITableView it can scroll everywhere). Do I need to implement accessibilityFrame as a message that checks the position of UIViews every time it is called?
source share