iPhoneアプリは現在IOS 8/9/10をサポートしています。カスタムUITableViewCellのアクセシビリティ上の声をサポートするのが難しいです。私は以下のSOの記事を読んだが、提案のどれも働いていない。個々のコンポーネントにアクセス可能にしたい。私にとっては残念ながらカスタムUITableViewCellのボイスオーバーアクセシビリティを設定できません
- Custom UITableview cell accessibility not working correctly
- Custom UITableViewCell trouble with UIAccessibility elements
- Accessibility in custom drawn UITableViewCell
- https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/iPhoneAccessibility/Making_Application_Accessible/Making_Application_Accessible.html#//apple_ref/doc/uid/TP40008785-CH102-SW10
- http://useyourloaf.com/blog/voiceover-accessibility/
、セルは、アクセシビリティインスペクタによって検出されていません。テーブルビューのセル内の個々の要素を取り上げるためのアクセシビリティを声高にする方法はありますか?デバイスとシミュレータの両方でこの問題をデバッグすると、XCodeがisAccessibleElement
関数を呼び出すことがわかりました。関数がNO
を返した場合、残りのメソッドはスキップされます。私はXcodeでIOS 9.3をテストしています。
私のカスタムテーブルビューセルは、以下のようにラベルとスイッチで構成されています。スイッチは、カスタムアクセサリビューに追加されている間
ラベルは、コンテンツビューに追加されます。
インタフェース定義は、実装ブロックはあなたが説明したパターンから、私はあなたがしたいと思う理由はわからないんだけど、全ての
@interface MyCustomTableViewCell()
@property (nonatomic, strong) UIView *customAccessoryView;
@property (nonatomic, strong) NSString *alertTextString;
@property (nonatomic, strong) NSMutableArray* accessibleElements;
@end
@implementation MyCustomTableViewCell
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
if(self = [super initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:reuseIdentifier]) {
[self configureTableCell];
}
return self;
}
- (void)configureTableCell
{
if (!_accessibleElements) {
_accessibleElements = [[NSMutableArray alloc] init];
}
//Alert label
self.alertLabel = [[self class] makeAlertLabel];
[self.contentView setIsAccessibilityElement:YES];
//
[self.contentView addSubview:self.alertLabel];
// Custom AccessoryView for easy styling.
self.customAccessoryView = [[UIView alloc] initWithFrame:CGRectZero];
[self.customAccessoryView setIsAccessibilityElement:YES];
[self.contentView addSubview:self.customAccessoryView];
//switch
self.switch = [[BAUISwitch alloc] initWithFrame:CGRectZero];
[self.switch addTarget:self action:@selector(switchWasFlipped:) forControlEvents:UIControlEventValueChanged];
[self.switch setIsAccessibilityElement:YES];
[self.switch setAccessibilityTraits:UIAccessibilityTraitButton];
[self.switch setAccessibilityLabel:@""];
[self.switch setAccessibilityHint:@""];
self.switch.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[self.customAccessoryView addSubview:self.switch];
}
+ (UILabel *)makeAlertLabel
{
UILabel *alertLabel = [[UILabel alloc] initWithFrame:CGRectZero];
alertLabel.backgroundColor = [UIColor clearColor];
alertLabel.HTMLText = @"";
alertLabel.numberOfLines = 0;
alertLabel.lineBreakMode = LINE_BREAK_WORD_WRAP
[alertLabel setIsAccessibilityElement:YES];
return alertLabel;
}
-(void)setAlertHTMLText:(NSString*)title{
_alertTextString = [NSString stringWithString:title];
[self.alertLabel setText:_alertTextString];
}
- (BOOL)isAccessibilityElement {
return NO;
}
// The view encapsulates the following elements for the purposes of
// accessibility.
-(NSArray*) accessibleElements {
if (_accessibleElements && [_accessibleElements count] > 0) {
[_accessibleElements removeAllObjects];
}
// Fetch a new copy as the values may have changed.
_accessibleElements = [[NSMutableArray alloc] init];
UIAccessibilityElement* alertLabelElement =
[[UIAccessibilityElement alloc] initWithAccessibilityContainer:self];
//alertLabelElement.accessibilityFrame = [self convertRect:self.contentView.frame toView:nil];
alertLabelElement.accessibilityLabel = _alertTextString;
alertLabelElement.accessibilityTraits = UIAccessibilityTraitStaticText;
[_accessibleElements addObject:alertLabelElement];
UIAccessibilityElement* switchElement =
[[UIAccessibilityElement alloc] initWithAccessibilityContainer:self];
// switchElement.accessibilityFrame = [self convertRect:self.customAccessoryView.frame toView:nil];
switchElement.accessibilityTraits = UIAccessibilityTraitButton;
// If you want custom values, just override it in the invoking function.
NSMutableString* accessibilityString =
[NSMutableString stringWithString:self.accessibilityPrefix];
[accessibilityString appendString:@" Switch "];
if (self.switchh.isOn) {
[accessibilityString appendString:@"On"];
} else {
[accessibilityString appendString:@"Off"];
}
switchElement.accessibilityLabel = [accessibilityString copy];
[_accessibleElements addObject:switchElement];
}
return _accessibleElements;
}
// In case accessibleElements is not initialized.
- (void) initializeAccessibleElements {
_accessibleElements = [self accessibleElements];
}
- (NSInteger)accessibilityElementCount
{
return [_accessibleElements count]
}
- (id)accessibilityElementAtIndex:(NSInteger)index
{
[self initializeAccessibleElements];
return [_accessibleElements objectAtIndex:index];
}
- (NSInteger)indexOfAccessibilityElement:(id)element
{
[self initializeAccessibleElements];
return [_accessibleElements indexOfObject:element];
}
@end
は、uは、テーブルビューとセルのアクセシビリティを設定しましたか。それに関連するコードを表示します。 –
また、あなたがあなただけaccessibleElementsプロパティに配列を渡すことができ、accessibleElementsをオーバーライドする必要がいけない。 –
@TejaNandamuriこれはコンテナビューであるため、 "isAccessibleElement"のテーブルビューコンテナセルのアクセシビリティを "いいえ"に設定しました。そのコードブロックはコードブロックで提供されます。あなたの2番目のコメントには、ユーザーがスイッチを動かせるようになるたびにaccessibleElementsを計算する必要があります。それが起こった場合、私はその価値を反映しています。 – Kartik