11

I implemented trailing swipe actions using new iOS 11 UISwipeActionsConfiguration API, and I can reveal them by swiping from the edge, can swipe all the way to the left side etc.

But I can't hide those actions by swiping back to original position. If I drag a little bit to the left and then back to the right it does dismiss (see gif). It also gets dismissed by tapping on a cell.

The official Mail app does support dragging to hide swipe actions, so there may be a way in the API too.

See sample project here: https://github.com/nezhyborets/ios-case-study-playgrounds/tree/master/UISwipeActionsConfiguration

enter image description here

2 Answers2

11

Great question!

This is not a direct configuration, but if you also implement an action for leading in addition to your existing 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])
}

This will give you the desired effect.

Unfortunately, this requires an action for swiping right. I tried making the actions array [], but that doesn't do anything.

Aaron
  • 400
  • 3
  • 14
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)
}
Aaron
  • 400
  • 3
  • 14