UITableViewCell
안에 사용자 정의보기를 넣으려고합니다. 물론 UITableView
내에 있습니다. 이 사용자 정의보기를 액세스 가능하게 만들고 싶습니다. UIAccessibilityContainer
(자체 UIView로 구현되지 않은 몇 가지 시각적 요소가 포함되어 있으므로)을 만들어야합니다.테이블보기의 UIAccessibilityContainer
이렇게하면 테이블이 스크롤 될 때마다 요소의 위치가 엉망이됩니다. VoiceOver를 사용하여 요소를 페이징하는 동안 선택한 요소를 화면 중앙에 놓기 위해 테이블을 자동으로 스크롤하지만, VoiceOver가 요소가 더 이상 시각적으로 어디에 있지 않다고 생각하는지에 대한 개요를 표시합니다. 그것은 자동 스크롤하기 전에이 행 사가 어디 될 일이 있기 때문에 관리자는 말한다 스크린 샷
주 "행 4 요소 (2)"만 강조 표시된 지역은 행 7의 어떤 임의의 장소입니다 탁자. '
나의 생각은 내가 테이블 뷰 스크롤,하지만 난이 UIAccessibilityContainer
를 사용하지 않는 경우 그렇게 할 필요가 없습니다 때 레이아웃 변경을 게시 할 UIAccessibilityPostNotification()
을 사용해야 할 수도 있다는 것입니다 내가 shouldn처럼 느낀다 t는 그것을해야하고 시스템이 나를 위해 이것을 처리해야한다는 것을 의미합니다. 그러나 UIAccessibilityElement
이 화면 좌표로 설정된 accessibilityFrame
을 가질 필요가 있다는 사실은 사물에 주름을 던진 것처럼 보입니다. (보너스 질문 : 왜 그런 식의 API가 디자인 되었습니까? 요소의 컨테이너 또는 그와 유사한 프레임과 관련하여 프레임을 정의하는 이유는 무엇입니까? Arg)
다음과 같은 경우에 사용자 정의보기의 구현이 있습니다. 문제를 일으킨다. 전체 프로젝트 (Xcode 4)의 경우 click here.
@implementation CellView
@synthesize row=_row;
- (void)dealloc
{
[_accessibleElements release];
[super dealloc];
}
- (void)setRow:(NSInteger)newRow
{
_row = newRow;
[_accessibleElements release];
_accessibleElements = [[NSMutableArray arrayWithCapacity:0] retain];
for (NSInteger i=0; i<=_row; i++) {
UIAccessibilityElement *element = [[UIAccessibilityElement alloc] initWithAccessibilityContainer:self];
element.accessibilityValue = [NSString stringWithFormat:@"Row %d, element %d", _row, i];
[_accessibleElements addObject:element];
[element release];
}
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect
{
[[UIColor lightGrayColor] setFill];
UIRectFill(self.bounds);
[[UIColor blackColor] setFill];
NSString *info = [NSString stringWithFormat:@"Row: %d", _row];
[info drawAtPoint:CGPointZero withFont:[UIFont systemFontOfSize:12]];
[[[UIColor whiteColor] colorWithAlphaComponent:0.5] setFill];
NSInteger x=0, y=0;
for (NSInteger i=0; i<=_row; i++) {
CGRect rect = CGRectMake(12+x, 22+y, 30, 30);
UIAccessibilityElement *element = [_accessibleElements objectAtIndex:i];
element.accessibilityFrame = [self.window convertRect:[self convertRect:rect toView:self.window] toWindow:nil];
UIRectFill(rect);
x += 44;
if (x >= 300) {
x = 0;
y += 37;
}
}
}
- (BOOL)isAccessibilityElement
{
return NO;
}
- (NSInteger)accessibilityElementCount
{
return [_accessibleElements count];
}
- (id)accessibilityElementAtIndex:(NSInteger)index
{
return [_accessibleElements objectAtIndex:index];
}
- (NSInteger)indexOfAccessibilityElement:(id)element
{
return [_accessibleElements indexOfObject:element];
}
@end
편집 : 나는 업데이트 변화를 시도했습니다 있음을 유의 요소의 accessibilityFrame
-indexOfAccessibilityElement:
과 -accessibilityElementAtIndex:
의 아이디어와 그것을 필요로하고 그 것 때마다 VoiceOver를 어떻게 든 요소를 요청할 것 사물을 업데이 트하는 좋은 시간. 그러나 그것도 작동하지 않는 것 같습니다. VoiceOver가 자동으로 다시 그리기를 요청하기를 바랬습니다.하지만 작동하지 않는 것 같습니다. (-drawRect:
에 위치 설정 코드를 넣는 아이디어는 WWDC에서 내가 기억하는 것으로부터 나온 것이지만, 그것이 "우수 사례"인지 또는 단지 우연한 일인지 분명하지 않았습니다.
시뮬레이터의 버그뿐 아니라 실제 장치에서의 동작을 확인 했습니까? –
예, 기기에서 제대로 작동하지 않습니다. 그것은 조금 다르게 행동하지만, 여전히 내가 기대했던 방식은 아닙니다. – Sean