如何在行的滑动操作配置中为VoiceOver添加辅助功能标签? [英] How to add accessibility label for VoiceOver at Swipe Action Configuration for Row?

查看:181
本文介绍了如何在行的滑动操作配置中为VoiceOver添加辅助功能标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Swift 4创建一个iOS应用程序而我没有使用Storyboard。
要从表视图控制器中删除一行,用户会向左滑动该行,然后单击删除按钮。

I'm creating an iOS App using Swift 4 and I'm not using Storyboards. To delete a row from the Table View Controller the user swipe left the row and then click the Delete Button.

这是我正在使用的代码实现(没有使用外部库):

Here is the code I'm using to implement that (no external libraries have been used):

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    self.isAccessibilityElement = true
    self.accessibilityLabel = "Delete row"


    let deleteAction = UIContextualAction(style: .normal , title: "DELETE") { (action, view, handler) in

        self.removeRowFromMyList(indexPath: indexPath.row)

        MyListController.stations.remove(at: indexPath.row)
        self.tableView.deleteRows(at: [indexPath], with: .automatic)

        self.tableView.setEditing(false, animated: true)
        self.tableView.reloadData()
    }
    let swipeAction = UISwipeActionsConfiguration(actions: [deleteAction])
    swipeAction.performsFirstActionWithFullSwipe = false

    return swipeAction
}

我确实检查了其他问题,但没有人提出这个问题。
如果您需要了解解决此问题的任何其他信息,请随时在此处发表评论。
谢谢:)

I did check other questions and none of them address that. Please don't hesitate to comment here for any other information you need to know to solve this issue. Thanks :)

推荐答案

使用 Apple的UIAccessibility

您只需设置辅助功能自定义操作:

You just need to set Accessibility Custom Action:

cell.accessibilityCustomActions = [UIAccessibilityCustomAction(name: "Delete", target: self, selector: #selector(theCustomAction))]


@objc private func theCustomAction() -> Bool {
    //Do anything you want here
    return true
}

更新:

所以我确实重新创建了项目,但这次我使用了Storyboard(我不是最后一次)我从Cocoapods导入了 SwipeCellKit Library ,我按照他们的文档和VoiceOver完美地删除了一个单元格从他们indexPath.row没有问题。

So I did recreate the project but this time I was using Storyboards (I wasn't the last time) and I imported from Cocoapods the SwipeCellKit Library and I followed their documentation and VoiceOver was working perfectly fine with deleting a cell from them indexPath.row with no problem.

这篇关于如何在行的滑动操作配置中为VoiceOver添加辅助功能标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆