我有被定位在视觉上直观地但在由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;
}
Answer 1:
最简单的答案,这在于创造一个UIView
包含您的按钮,并响应不同,从系统的辅助功能调用子类。 这些重要的电话是:
-(NSInteger)accessibilityElementCount
-(id)accessibilityElementAtIndex:
-(NSInteger)indexOfAccessibilityElement:
我已经看到了其中的几个问题,并回答过一个 ,但我从来没见过的如何重新排序VoiceOver的焦点一般示例。 因此,这里是如何创建一个实例UIView
子类,按标签暴露其可访问的子视图的VoiceOver。
AccessibilitySubviewsOrderedByTag.h
#import <UIKit/UIKit.h>
@interface AccessibilitySubviewsOrderedByTag : UIView
@end
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
现在,只需括在这种观点的一个实例你的按钮,并设置你的按钮标签属性是基本的焦点顺序。
Answer 2:
您可以更改顺序设置视图的accessibilityElements阵:
self.view.accessibilityElements = @[self.view1, self.view2, self.view3, self.view4];
要么
self.anotherView.accessibilityElements = @[self.label1, self.txtView1, self.label2, self.txtView2];
如果您需要设置启用的互动程序:
[self.view1 setUserInteractionEnabled:YES];
如果视图是隐藏的配音也不会通过。
Answer 3:
在斯威夫特你只需要设置视图的accessiblityElements数组属性:
view.accessibilityElements = [view1, view2, view3]
//为了您希望
Answer 4:
我试图韦斯利的答案设置的阵列的accessibilityElements
但它并没有为我工作。
苹果公司有一些文档加强表格视图单元的辅助功能 ,在代码的例子。 基本上你设置单元格(父视图),以子视图的辅助功能标签的值的可访问性标签。
[cell setAccessibilityLabel:[NSString stringWithFormat:@"%@, %@", cityLabel, temperatureLabel]];
这是对我工作。
Answer 5:
这并不直接回答原来的问题,但它回答了这个问题的标题:
当我想的VoiceOver向下滑动列,我已经使用了与列含有视图shouldGroupAccessibilityChildren
集。
我希望我早知道这样早,因为它可以是一个痛苦的追溯插入容器到自动版式的情况...
Answer 6:
我知道这是一个古老的线程,但我发现,这样做最简单的方法是子类的UIView这样(SWIFT 3)。 然后,只需修改你的故事板主要UIView的类型AccessibiltySubviewsOrderedByTag和更新标签要在顺序读取每个子视图。
类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})
}
}
Answer 7:
我想你可以在故事板做。 通过VoiceOver顺序由在文档大纲视图的顺序确定。
只需拖放在视图层次的意见,正确的顺序。
编辑:
对不起,我不能发表screenhots直到10声誉。 在故事板,文档大纲是在哪里与他们的子视图您的场景中所列的左侧区域。 在这里,子视图是有序的一个低于对方。 当您更改此顺序时,VoiceOver的阅读顺序将发生变化。
Answer 8:
我昨天发现了一个方便的途径。 类似@TejAces的回答。 创建一个新的快捷文件,然后将这些东西复制到它。
import UIKit
extension UIView {
func updateOrder(_ direction: Bool = true) {
var tempElements: [Any]? = [Any]()
let views = (direction) ? subviews : subviews.reversed()
for aView in views {
tempElements?.append(aView)
}
accessibilityElements = tempElements
}
}
class ReorderAccessibilityByStoryBoardView: UIView {
override func didAddSubview(_ subview: UIView) {
updateOrder()
}
}
设置了UIView(包含要重新排序的意见)的类作为ReorderAccessibilityByStoryBoardView。 然后你就可以重新排序故事板的视图列表重新排序。
由于子视图不包含StackView /滚动型的观点,你需要做一个独立的阶级在这个文件中。 如ReorderAccessibilityByStoryBoardStackView楼下。
class ReorderAccessibilityByStoryBoardStackView: UIStackView {
override func didAddSubview(_ subview: UIView) {
updateOrder(false)
}
}
有了这些代码,您还可以通过特定的顺序将它们重新排序的代码添加视图的。
文章来源: Change order of read items with VoiceOver