ios - 滑动单元格时如何隐藏其他滑动单元格操作

标签 ios swift uitableview swipe

我有一个带有原生 SwipeCell 功能的 tableView。 当用户轻扫单元格时,我有两个操作(删除和编辑)。 当您一直滑动单元格时,它会移动删除按钮(如预期的那样),问题是 - 背景是透明的,因此当删除按钮位于编辑图标上方时,它看起来很糟糕。

@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let deleteAction = UIContextualAction(style: .normal, title: nil) { [weak self] (action, view, complete) in

        self?.deleteAction(tableView, at: indexPath)
        complete(true)
    }
    if let cgImageX =  #imageLiteral(resourceName: "alarmDelete").cgImage {
        deleteAction.image = ImageWithoutRender(cgImage: cgImageX, scale: UIScreen.main.nativeScale, orientation: .up)
    }
    deleteAction.backgroundColor = UIColor.white.withAlphaComponent(0)

    let editAction = UIContextualAction(style: .normal, title: nil) { [weak self] (action, view, complete) in
        self?.editAction(tableView, at: indexPath)
        complete(true)
    }
    if let editImage =  #imageLiteral(resourceName: "edit").cgImage {
        editAction.image = ImageWithoutRender(cgImage: editImage, scale: UIScreen.main.nativeScale, orientation: .up)
    }
    editAction.backgroundColor = UIColor.white.withAlphaComponent(0)
    return UISwipeActionsConfiguration(actions: [deleteAction, editAction])
}

是否可以在cell一路移动的时候隐藏其他 Action ? Exibit A Exibit B

视频:https://i.imgur.com/9betbst.mp4

谢谢

最佳答案

您应该按如下方式更新您的代码以解决您的问题。

let swipeActionConfig = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
swipeActionConfig.performsFirstActionWithFullSwipe = false
return swipeActionConfig

但是,这将阻止在完全滑动时执行第一个操作,这意味着当将单元格滑动到更多后,您将无法执行第一个操作显示。

关于ios - 滑动单元格时如何隐藏其他滑动单元格操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56990205/

相关文章:

ios - 如何正确发布 `UIDeviceOrientationDidChangeNotification`?

ios - WebRTC 信号状态永远不会在 iOS 上更改为 HaveLocalAnswer

ios - Xcode 从 @2x 版本创建的非视网膜图像的质量如何?

swift - 如果结构项等于 nil

xcode - TTTAttributedLabel addLinkToURL NSRange 混淆

ios - 使用 performSegue 显示导航 Controller

ios - 如何提高具有过多 UITextView 的 UITableViewCell 的性能?

ios - iOS中需要控制UIImageView在UITableView上的移动

ios - DynamicCastClassUnconditional 与自定义单元类

ios - SceneKit - 在不使用单独的 SCNRenderer 的情况下从 SCNView 获取渲染场景作为 MTLTexture