On Dec 2, 2011, at 12:28 PM, Fritz Anderson wrote:
On 1 Dec 2011, at 1:55 PM, Chris Fleizach wrote:
You still need to convert the frame to the window... This assumes that framElem starts out being the coordinate space of the view itself. So
First manipulate it to get the size of the object in the coordinate space of the view.
CGRect frameElem = self.bounds;
// assumes object is half width of real object
frameElem.size.width = framElem.size.width/2;
// now convert to window space
UIWindow *window = [self window];
frameElem = [view convertRect:frameElem toView:window];
frameElem = [window convertRect:frameElem toWindow:nil];
elem.accessibilityFrame = frameElem;
I don't think the fact that your icons have frames that are 20 px off is a good reason to "abandon" accessibility.
The problem exists because the frame is calculated and stored when you have a full screen image present, so at that point the status bar is not being considered. Then presumably that view goes away and you're left with an incorrect frame.
I think you should subclass UIAccessibilityElement and override accessibilityFrame to provide the answer when it is requested, rather than trying to update the elements whenever there's a change. This is usually what I do.
Hence
@implemenentation MyUIAXElement
- (CGRect)accessibilityFrame
{
CGRect frame = [self.accessibilityContainer rectForSegment: self.myIndex];
// rectForSegment: derives a CGRect from self.bounds.
frame = [self convertRect: frame toView: self.window];
frame = [self.window convertRect: frame toWindow: nil];
}
@end
Please let us know if that works.
Thanks
I renew my question. I tried what you suggested, and it doesn't work. Exactly the same error occurs: The accessibility frames are origin.y+20 offset from their correct positions.
I think it's screwing up my hit-tests on touch events as well.
All problems clear if I redraw the problem view (after putting up and tearing down a near-full-screen image view, and using an AVAudioRecorder). There are no problems whatsoever with drawing code, and no problems if accessibility is off.
I append my code.
Again: What's my next step? Do you have advice? Should I file a bug? Do I have to burn a DTS incident?
Or do I have to abandon accessibility altogether? That's going to be trouble, as my institution takes accessibility seriously, and I'll be disappointed if I can't do the right thing. But if it's not technically feasible, they'll take my word for it, and hope we don't get sued.
Xcode 4.2, iOS SDK 5.0, targeting iOS 4.3, error manifests on simulator 4.3 and device 5.0, ARC.
— F
- (void) updateAccessibilityElements
{
NSUInteger count = [self.dataSource
countForSegmentView: self];
UIAccessibilityElement * elem;
CGRect frameElem;
double totalTime = 0.0;
self.accArray = [NSMutableArray arrayWithCapacity: count];
for (int i = 0; i < count; i++) {
elem = [[UIAccessibilityElement alloc]
initWithAccessibilityContainer: self];
[self.accArray addObject: elem];
double duration;
BOOL isMaster;
duration = [self.dataSource segmentView: self
durationForSegmentAtIndex: i
isMaster: &isMaster];
elem.accessibilityLabel = [NSString stringWithFormat:
@"%s segment, %.1f seconds at %.1f, %s",
isMaster? "Master": "Student",
duration, totalTime,
[self.selectedSegmentSet containsIndex: i]?
"selected": "not selected"];
elem.accessibilityHint =
@"Double-tap to select, triple-tap to move here.";
totalTime += duration;
frameElem = [self rectForSegment: i];
// rectForSegment: derives a CGRect from self.bounds.
frameElem = [self convertRect: frameElem toView: self.window];
frameElem = [self.window convertRect: frameElem toWindow: nil];
elem.accessibilityFrame = frameElem;
}
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification,
nil);
}