Ios SwipeCellKit不滑动单元格

Ios SwipeCellKit不滑动单元格,ios,swift,uicollectionview,uicollectionviewcell,Ios,Swift,Uicollectionview,Uicollectionviewcell,我想为UICollectionView实现UITableView的UIWipeActionsConfiguration。为了做到这一点,我正在使用 MyUICollectionView采用SwipeCollectionViewCellDelegate协议。并且该单元格继承自SwipeCollectionViewCell 带有UICollectionView的ViewController 这样做之后,当我滑动单元格时,deleteAction与单元格内容重叠 如屏幕截图所示,单元格内容与del

我想为
UICollectionView
实现UITableView的
UIWipeActionsConfiguration
。为了做到这一点,我正在使用


My
UICollectionView
采用
SwipeCollectionViewCellDelegate
协议。并且该单元格继承自
SwipeCollectionViewCell

带有UICollectionView的ViewController 这样做之后,当我滑动单元格时,
deleteAction
与单元格内容重叠

如屏幕截图所示,单元格内容与
deleteAction
文本重叠

更新
setConstraints
将视图的
translatesAutoResizingMacSkintoConstraints
设置为
false
必须将名称标签添加到
contentView
。 改变

结果:

我想问题可能出在单元格中的UILabel中,也许您可以尝试(label.clipsToBounds=true),这样它就不会出现在容器视图中。@omar否,即使我在左侧或右侧使用img或20X20 uiview,也会出现同样的问题。请尝试将您的
UILabel
添加到单元格的
contentView
中。@mahan我的回答解决了您的问题吗?@mahan我想在滑动时,库会调整单元格的contentView,然后我用您的示例代码进行了尝试。它确实起作用了
class SwipeViewController: UIViewController {

    lazy var collectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .vertical
        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
        collectionView.register(SwipeableCollectionViewCell.self, forCellWithReuseIdentifier: SwipeableCollectionViewCell.identifier)
        collectionView.showsVerticalScrollIndicator = false
        collectionView.contentInset = UIEdgeInsets(top: 8, left: 0, bottom: 4, right: 0)
        collectionView.backgroundColor = UIColor(white: 0.97, alpha: 1)
        collectionView.dataSource = self
        collectionView.delegate = self
        return collectionView
    }()

    var items: [String] = {
        var items = [String]()
        for i in 1 ..< 20 {
            items.append("Item \(i)")
        }
        return items
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(collectionView)
        collectionView.setConstraints(topAnchor: view.topAnchor,
                              leadingAnchor: view.leadingAnchor,
                              bottomAnchor: view.bottomAnchor,
                              trailingAnchor: view.trailingAnchor,
                              leadingConstant: 10,
                              trailingConstant: 10)
    }
}

extension SwipeViewController: UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: collectionView.frame.width, height: 80)
    }
}

extension SwipeViewController: UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return items.count
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SwipeableCollectionViewCell.identifier, for: indexPath) as! SwipeableCollectionViewCell
        cell.backgroundColor = BackgroundColor.colors[indexPath.row]
        cell.delegate = self
        return cell
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    }
}

extension SwipeViewController: SwipeCollectionViewCellDelegate {

    func collectionView(_ collectionView: UICollectionView, editActionsForItemAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
        guard orientation == .right else { return nil }

        let deleteAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in
        }


        return [deleteAction]
    }

}
class SwipeableCollectionViewCell: SwipeCollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)

        self.addSubview(nameLabel)

        nameLabel.setConstraints(topAnchor: self.topAnchor,
                         leadingAnchor: self.leadingAnchor,
                         bottomAnchor: self.bottomAnchor,
                         trailingAnchor: self.trailingAnchor)

        self.backgroundColor = .white
    }

    static let identifier = "TaskListTableViewCell"


    private let nameLabel: UILabel = {
        let label =  UILabel()
        label.text = "Simulator user has requested new graphics quality"
        label.numberOfLines = 0
        return label
    }()


    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
self.addSubview(nameLabel)

nameLabel.setConstraints(topAnchor: self.topAnchor,
            leadingAnchor: self.leadingAnchor,
            bottomAnchor: self.bottomAnchor,
            trailingAnchor: self.trailingAnchor)
self.contentView.addSubview(nameLabel)

nameLabel.setConstraints(topAnchor: self.contentView.topAnchor,
            leadingAnchor: self.contentView.leadingAnchor,
            bottomAnchor: self.contentView.bottomAnchor,
            trailingAnchor: self.contentView.trailingAnchor)