我使用
添加了滑动删除功能override func tableView(_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath)
-> UISwipeActionsConfiguration?
我正在通过解除/确认操作发出警报。一旦关闭,我想关闭滑动操作菜单。
override func tableView(_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteClosure:UIContextualAction.Handler = {
(action:UIContextualAction,
view:UIView,
completionHandler:(Bool) -> Void) in
let alert = self.confirmDeletion({ _ in
let row = indexPath.row;
let removed = self.logList.remove(at: row);
self.deleteLogEntry(removed);
//
tableView.reloadData();
//
}, declineBlock: {_ in
tableView.reloadData();// this hides it but w/o animation
});
DispatchQueue.main.async {
self.present(alert, animated: true, completion: nil);
}
}
let deleteAction = UIContextualAction(style: .destructive, title: "Delete", handler: deleteClosure);
return UISwipeActionsConfiguration(actions: [deleteAction]);
}
到目前为止,我发现重新加载表格数据将关闭尾部滑动菜单,但没有看起来很奇怪的动画。有没有办法告诉它用动画关闭?
** 关于重复的注意事项 ** 标记为与删除行后解雇无法按预期工作的问题重复,但此处情况并非如此。当用户取消删除并且行未删除时,我想取消尾随滑动。
我已经尝试过:
tableView.setEditing(false,animated: true);
- 没有明显差异tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.automatic);
- 行随动画向右移动,但按钮重叠tableView.resignFirstResponder();
- 没有明显的差异(我必须尝试)tableView.reloadTable()
- 滑动菜单被关闭,但没有动画效果
最佳答案
您需要使用结果调用completionHandler 来取消滑动操作。这是 UIContextualActionHandler 的帮助;
// call the completionHandler to reset the context to its normal state (e.g. when swiping, resets to unswiped state)
// pass YES to the completionHandler if the action was actually performed, to show a visual indication of the successful completion
typedef void (^UIContextualActionHandler)(UIContextualAction *action, __kindof UIView *sourceView, void(^completionHandler)(BOOL actionPerformed));
关于ios - 如何在取消时关闭滑动操作上下文菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55112175/