Ios 滑动以编程方式删除UICollectionViewCell
我正试图遵循这篇文章中的教程:完全一样,除了从故事板添加插座之外,我已经通过编程方式初始化了所有内容(包括我的集合视图) 当我到达包含集合视图的屏幕时,显示其下的删除按钮的滑动操作不会发生。我已将委托方法shoulldrecognizesimultaneousyWith设置为返回true,并已将单元格设置为:Ios 滑动以编程方式删除UICollectionViewCell,ios,uicollectionview,storyboard,constraints,nslayoutconstraint,Ios,Uicollectionview,Storyboard,Constraints,Nslayoutconstraint,我正试图遵循这篇文章中的教程:完全一样,除了从故事板添加插座之外,我已经通过编程方式初始化了所有内容(包括我的集合视图) 当我到达包含集合视图的屏幕时,显示其下的删除按钮的滑动操作不会发生。我已将委托方法shoulldrecognizesimultaneousyWith设置为返回true,并已将单元格设置为: import UIKit class CustomCollectionViewCell: UICollectionViewCell, UIGestureRecognizerDelegat
import UIKit
class CustomCollectionViewCell: UICollectionViewCell, UIGestureRecognizerDelegate {
// Cell data
var aLabel : UILabel!
var bLabel : UILabel!
var myImageView : UIImageView!
var myContentView: UIView!
// Swipe to delete cell
var contentViewLeftConstraint : NSLayoutConstraint!
var contentViewRightConstraint : NSLayoutConstraint!
var deleteButton : UIButton!
var startPoint = CGPoint()
var startingRightLayoutConstraintConstant = CGFloat()
var swipeView : UIView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
backgroundColor = .clear
myImageView = UIImageView(frame: CGRect(
x : 15,
y : 10,
width : frame.height - 20,
height: frame.height - 20
))
aLabel = UILabel(frame: CGRect(
x : myImageView.frame.maxX + 15,
y : 15,
width : frame.width - 20 - myImageView.frame.maxX,
height: 23
))
bLabel = UILabel(frame: CGRect(
x : myImageView.frame.maxX + 15,
y : aLabel.frame.maxY,
width : frame.width - 20 - myImageView.frame.maxX,
height: 30
))
swipeView = UIView(frame: CGRect(
x : contentView.frame.width - 60,
y : contentView.frame.minY,
width : 60,
height: contentView.frame.height
))
deleteButton = UIButton(frame: swipeView.frame)
deleteButton.backgroundColor = .red // For visibility purposes
swipeView.addSubview(deleteButton)
myContentView = UIView(frame: contentView.frame)
myContentView.addSubview(myImageView)
myContentView.addSubview(aLabel)
myContentView.addSubview(bLabel)
contentView.addSubview(swipeView)
contentView.addSubview(myContentView)
// Pin the song data content view's left margin to the cell content view's left margin.
contentViewLeftConstraint = NSLayoutConstraint(
item : myContentView,
attribute : .left,
relatedBy : .equal,
toItem : contentView,
attribute : .leftMargin,
multiplier: 1.0,
constant : 0.0
)
contentViewLeftConstraint.isActive = true
// Pin the song data content view's right margin to the cell content view's right margin.
contentViewRightConstraint = NSLayoutConstraint(
item : myContentView,
attribute : .right,
relatedBy : .equal,
toItem : contentView,
attribute : .rightMargin,
multiplier: 1.0,
constant : 0.0
)
contentViewRightConstraint.isActive = true
}
}
我的ViewController方法与教程中的方法完全相同。我打印出了平移运动,就像它在中完成一样,平移手势的行为符合预期。只是myContentView
不会向左滑动以显示删除按钮。也许我设置的约束不正确
请帮忙