在UITableViewCell中自定义VoiceOver操作

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

有没有一种方法可以将自定义的VoiceOver操作添加到单元格中?

默认情况下,即使表视图委托在tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:方法中返回自定义标题,也会将其读出为“删除”。 如何让VoiceOver读出自定义操作标题?

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

更新 :从iOS 8开始,您可以设置/实现accessibilityCustomActions属性来返回UIAccessibilityCustomAction对象的数组(注意除了您提供的内容之外,VoiceOver仍然会在其UI中添加“激活项目”默认操作)。

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

像往常一样使用Swift和select器,不要忘记添加@objc属性到Swift中的自定义动作的目标方法,如果你不子类NSObject /方法是私人的,否则试图激活与VoiceOver的行动,它不会做任何事情,并发挥“达到边界”的声音(至less在iOS 8.2和8.3,我testing了NSObject子类的目标对象)。

关于你的第二个问题 – 感觉像一个错误,你可以再次提交一个雷达:-)

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);