I have a UI开发者_如何学GoControl subclass which follows the UIAccessibilityContainer informal protocol: it returns NO to -isAccessibilityElement, delivers the correct -accessibilityElementCount and elements in the accessors.
Each UIAccessibilityElement which is created to represent an accessibility region is created successfully, and the frame is a 1:1 mapping of another CGRect I'm drawing.
E.g., I'm drawing into {94, 99}, {209, 350}} and the -accessibilityFrame on the UIAccessibilityElement is set to the same CGRect value.
However, when in landscape (or upside-down portrait) orientation, the frames (only for accessibility elements, drawing still works fine) are rotated incorrectly. The top-left point relative to the frame is always the corner top-left of the home button.
Here's a screenshot from the simulator:
As you can see, it's in landscape mode, and the frame is totally impossibly not what it's specifying.
Here's the code driving the creation of the elements:
CGRect localRect = someCGRectVariable;
CGRect globalRect = CGRectOffset(localRect, CGRectGetMinX(self.accessibilityFrame), CGRectGetMinY(self.accessibilityFrame));
UIAccessibilityElement *accElem = [[UIAccessibilityElement alloc]initWithAccessibilityContainer:self];
accElem.isAccessibilityElement = YES;
accElem.accessibilityFrame = globalRect;
accElem.accessibilityHint = [NSString stringWithFormat:NSLocalizedString(@"xyz %@", nil), someName];
accElem.accessibilityTraits = UIAccessibilityTraitButton;
accElem.accessibilityLabel = nameValue;
It looks to me like the rotation is busted, but I can't put my finger on it. It's worth noting that it works perfectly fine in portrait mode.
accessibilityFrame returns its answer in screen coordinates, without adjusting for device rotation.
Somewhere in Apple's docs it suggests you use [UIWindow convertRect:toWindow:] in this sort of case.
精彩评论