【问题标题】:Programmatically determine order in which UIView items should be read by VoiceOver以编程方式确定 VoiceOver 读取 UIView 项目的顺序
【发布时间】:2011-10-22 04:27:19
【问题描述】:

我正在使我的 iPhone 应用程序可访问。 VoiceOver 非常令人印象深刻。当用户使用 VoiceOver 时,它会自动读出屏幕上的项目,并允许用户双击屏幕上的任意位置来选择该项目。但是,我希望 VoiceOver 以特定顺序读取项目,但它始终以 UINavigationBar 项目开头,包括后退按钮。我根本不想阅读这些项目,我只想从特定项目开始。是否存在与“firstResponder”等效的 VoiceOver?

【问题讨论】:

    标签: iphone ios ipod-touch first-responder voiceover


    【解决方案1】:

    是的

    有一个名为UIAccessibilityContainer 的协议由 NSObject 实现。它使您可以使用以下三种方法自定义容器行为:

    • accessibilityElementCount
    • accessibilityElementAtIndex:
    • indexOfAccessibilityElement:

    如果您有一个想要控制可访问性元素顺序的主视图,您只需实现这三个方法并返回合适的视图/索引。另一件事是容器视图本身不能是可访问性元素,因此您应该覆盖isAccessibilityElement:并返回NO

    - (BOOL)isAccessibilityElement {
        return NO;
    }
    

    示例实现

    我建议您要么按照希望它们出现的顺序排列所有视图,要么使用tag 属性(如果您不将其用于其他任何用途)。协议的实现变得超级简单。

    元素数组

    我假设您有一个名为 accessibleElements 的数组,它以正确的顺序存储元素。

    - (NSInteger)accessibilityElementCount {
        return self.accessibleElements.count;
    }
    
    - (id)accessibilityElementAtIndex:(NSInteger)index {
        return self.accessibleElements[index]; 
    }
    
    - (NSInteger)indexOfAccessibilityElement:(id)element {
        return [self.accessibleElements indexOfObject:element];
    }
    

    标记元素

    我假设您的子视图被连续标记,从 0 到子视图的数量。

    - (NSInteger)accessibilityElementCount {
        return self.subviews.count;
    }
    
    - (id)accessibilityElementAtIndex:(NSInteger)index {
        // Not that self should have a tag<0 or tag>count otherwise it will 
        // return itself for that tag instead of the element you want it to.
        return [self viewWithTag:index]; 
    }
    
    - (NSInteger)indexOfAccessibilityElement:(id)element {
        return ((UIView *)element).tag;
    }
    

    【讨论】:

      【解决方案2】:

      在某些情况下,在一项上设置 UIAccessibilityTraitSummaryElement 可以做到这一点。 (我的游戏似乎太动态了,这无济于事。)

      【讨论】:

      • 或者可能不是——我可能误解了 UIAccessibilityTraitSummaryElement,它可能只是屏幕输入时所说的内容。这与焦点项目不同。
      猜你喜欢
      • 2016-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多