通过向后滑动关闭UISwipeActionsConfiguration

Ole*_*ets 7 uitableview uikit ios uiswipeactionsconfiguration

我使用新的iOS 11 UISwipeActionsConfigurationAPI 实现了拖尾滑动操作,我可以通过从边缘滑动来显示它们,可以一直滑动到左侧等.

但我无法通过刷回原来的位置来隐藏这些行为.如果我向左拖动一点然后向右拖动它会消失(参见gif).通过点击一个单元格也会被解雇.

官方邮件应用程序支持拖动以隐藏滑动操作,因此API中也可能有一种方法.

请参阅此处的示例项目:https://github.com/nezhyborets/ios-case-study-playgrounds/tree/master/UISwipeActionsConfiguration

在此输入图像描述

Aar*_*ron 7

好问题!

这不是直接配置,但如果您还要为leading现有的实施操作trailing:

func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let action = UIContextualAction(style: .normal, title: "bla") { (action, view, success) in
        success(true)
    }
    return UISwipeActionsConfiguration(actions: [action])
}
Run Code Online (Sandbox Code Playgroud)

这将为您提供所需的效果.

不幸的是,这需要一个向右滑动的动作.我尝试制作actions阵列[],但这没有做任何事情.


小智 6

// Create a destructive context action
let delete = UIContextualAction(style: .destructive, title: "Delete") { (myContext, myView, complete) in

    // Did what you wanted to do
    complete(true)

    // Cancelled the action
    complete(false)
}
Run Code Online (Sandbox Code Playgroud)