Mar*_*k S 29 accessibility ios voiceover
我在屏幕上有一堆按钮,这些按钮直观地定位,但不是由VoiceOver按直观顺序读取的.这是因为某些按钮(如向上和向下)位于彼此的上方和下方.然而,画外音似乎开始从左到右,从上到下阅读.
这导致画外音在"向上"之后读取"向上"右侧的按钮,而不是在之后立即读取"向下".
如何强制画外音读取我想要阅读的按钮?我应该提一下,我正在使用画外音上的滑动到循环元素功能.
我的所有按钮都是UIView和UIButton的子类.这是我使用的按钮启动器的示例.忽略像素数 - 我知道这是糟糕的形式,但我现在处于紧张状态:
UIButton* createSpecialButton(CGRect frame,
NSString* imageName,
NSString* activeImageName,
id target,
SEL obClickHandler)
{
UIButton* b = [UIButton buttonWithType:UIButtonTypeCustom];
[b setImage:[GlobalHelper nonCachedImage:imageName ofType:@"png"]
forState:UIControlStateNormal];
[b setImage:[GlobalHelper nonCachedImage:activeImageName ofType:@"png"]
forState:UIControlStateHighlighted];
[b addTarget:target action:obClickHandler forControlEvents:UIControlEventTouchUpInside];
b.frame= frame;
return b;
}
- (UIButton *) createSendButton {
CGFloat yMarker = 295;
UIButton* b = createSpecialButton(CGRectMake(160, yMarker, 70, 45),
@"Share_Btn",
@"Share_Selected_Btn",
self,
@selector(sendAction));
b.accessibilityHint = @"Send it!";
b.accessibilityLabel = @"Stuff for voiceover to be added";
[self.view addSubview:b];
return b;
}
Run Code Online (Sandbox Code Playgroud)
小智 37
您可以更改视图的accessibilityElements数组的顺序设置:
self.view.accessibilityElements = @[self.view1, self.view2, self.view3, self.view4];
Run Code Online (Sandbox Code Playgroud)
要么
self.anotherView.accessibilityElements = @[self.label1, self.txtView1, self.label2, self.txtView2];
Run Code Online (Sandbox Code Playgroud)
如果需要以编程方式设置交互:
[self.view1 setUserInteractionEnabled:YES];
Run Code Online (Sandbox Code Playgroud)
如果视图被隐藏,则语音将不会通过它.
NJo*_*nes 27
最简单的答案在于创建一个UIView
包含按钮的子类,并对来自系统的可访问性调用做出不同的响应.这些重要的电话是:
-(NSInteger)accessibilityElementCount
-(id)accessibilityElementAtIndex:
-(NSInteger)indexOfAccessibilityElement:
Run Code Online (Sandbox Code Playgroud)
我已经看过其中的一些问题,之前已经回答了一个问题,但我还没有看到如何重新排序VoiceOver焦点的一般示例.所以这里是一个如何创建UIView
子类的示例,该子类通过标记将其可访问的子视图公开给VoiceOver.
AccessibilitySubviewsOrderedByTag.h
#import <UIKit/UIKit.h>
@interface AccessibilitySubviewsOrderedByTag : UIView
@end
Run Code Online (Sandbox Code Playgroud)
AccessibilitySubviewsOrderedByTag.m
#import "AccessibilityDirectional.h"
@implementation AccessibilitySubviewsOrderedByTag {
NSMutableArray *_accessibilityElements;
}
//Lazy loading accessor, avoids instantiating in initWithCoder, initWithFrame, or init.
-(NSMutableArray *)accessibilityElements{
if (!_accessibilityElements){
_accessibilityElements = [[NSMutableArray alloc] init];
}
return _accessibilityElements;
}
// Required accessibility methods...
-(BOOL)isAccessibilityElement{
return NO;
}
-(NSInteger)accessibilityElementCount{
return [self accessibilityElements].count;
}
-(id)accessibilityElementAtIndex:(NSInteger)index{
return [[self accessibilityElements] objectAtIndex:index];
}
-(NSInteger)indexOfAccessibilityElement:(id)element{
return [[self accessibilityElements] indexOfObject:element];
}
// Handle added and removed subviews...
-(void)didAddSubview:(UIView *)subview{
[super didAddSubview:subview];
if ([subview isAccessibilityElement]){
// if the new subview is an accessibility element add it to the array and then sort the array.
NSMutableArray *accessibilityElements = [self accessibilityElements];
[accessibilityElements addObject:subview];
[accessibilityElements sortUsingComparator:^NSComparisonResult(id obj1, id obj2){
// Here we'll sort using the tag, but really any sort is possible.
NSInteger one = [(UIView *)obj1 tag];
NSInteger two = [(UIView *)obj2 tag];
if (one < two) return NSOrderedAscending;
if (one > two) return NSOrderedDescending;
return NSOrderedSame;
}];
}
}
-(void)willRemoveSubview:(UIView *)subview{
[super willRemoveSubview:subview];
// Clean up the array. No check since removeObject: is a safe call.
[[self accessibilityElements] removeObject:subview];
}
@end
Run Code Online (Sandbox Code Playgroud)
现在只需将按钮包含在此视图的实例中,并将按钮上的tag属性设置为焦点顺序.
在Swift中,您只需设置view的accessiblityElements数组属性:
view.accessibilityElements = [view1, view2, view3]
//你希望拥有的订单
我知道这是一个旧线程,但我发现最简单的方法是子类化UIView
. 然后只需将故事板中的主要UIView
类型修改为AccessibiltySubviewsOrderedByTag
并更新要按顺序阅读的每个子视图中的标签即可。
class AccessibilitySubviewsOrderedByTag: UIView {
override func layoutSubviews() {
self.accessibilityElements = [UIView]()
for accessibilitySubview in self.subviews {
if accessibilitySubview.isAccessibilityElement {
self.accessibilityElements?.append(accessibilitySubview)
}
}
self.accessibilityElements?.sort(by: {($0 as AnyObject).tag < ($1 as AnyObject).tag})
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
26573 次 |
最近记录: |