首页 文章

UITableViewCell中的自定义VoiceOver操作

提问于
浏览
8

UITableView 可编辑时,其 UITableViewCells 允许用户在启用VoiceOver时执行自定义操作 . 当VoiceOver光标在单元格上时,用户可以通过向上或向下滑动来听到可用的操作,然后通过双击屏幕上的任何位置来调用操作 . 我的单元格中只有两个可用的操作:删除(调用通常的单元格删除)和默认(调用单元格上的点按) . 我的问题是双重的:

有没有办法向单元格添加自定义VoiceOver操作?

默认情况下,即使表视图委托在 tableView:titleForDeleteConfirmationButtonForRowAtIndexPath: 方法中返回自定义 Headers ,Delete操作也会被读出"Delete" . 如何让VoiceOver读出自定义动作 Headers ?

2 回答

  • 10

    根本没有用于向VoiceOver提供自定义元素操作的API . 没有UIAccessibility *协议提供任何可能的东西 . 如果您需要添加自定义操作,我想您应该提交雷达,并希望Apple将在未来的iOS版本中实现它(或者它将在一个月内出现在iOS 7中) .

    UPDATE :从iOS 8开始,您可以设置/实现accessibilityCustomActions属性以返回UIAccessibilityCustomAction对象的数组(请注意,除了您提供的内容之外,VoiceOver仍会在其UI中添加"Activate Item"默认操作 . ):

    self.accessibilityCustomActions = [
        UIAccessibilityCustomAction(name: NSLocalizedString("Close", comment: ""), target: self, selector: "didPressClose")
    ]
    ...
    @objc
    func didPressClose() -> Bool {
        ...
    }
    

    像往常一样使用Swift和选择器,如果你没有子类 NSObject /该方法是私有的,请不要忘记将@objc属性添加到Swift中自定义操作的目标方法,否则在尝试使用VoiceOver激活操作时,它将不会做任何事情并播放"end of bounds reached"声音(至少在iOS 8.2和8.3中我用目标对象测试了子类 NSObject ) .

    关于你的第二个问题 - 感觉就像一个你可以再次提出雷达的bug :-)

  • 3

    iOS 8添加了对应用程序定义的自定义操作的支持 . 来自 UIAccessibility.h

    /*
     Return an array of UIAccessibilityCustomAction objects to make custom actions for an element accessible to an assistive technology.
     For example, a photo app might have a view that deletes its corresponding photo in response to a flick gesture.
     If the view returns a delete action from this property, VoiceOver and Switch Control users will be able to delete photos without performing the flick gesture.
     default == nil
     */
    @property (nonatomic, retain) NSArray *accessibilityCustomActions NS_AVAILABLE_IOS(8_0);
    

相关问题