我有一个UICollectionView根视图。
UICollectionView有一个名为 的自定义单元格HomeCell。
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath as IndexPath) as! HomeCell
在 HomeCell 我添加 bgView 和标题是这样的:
HomeCell 类:
class HomeCell: UICollectionViewCell {
var bgView = UIView()
var title = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
bgView.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
bgView.layer.cornerRadius = 20.0
bgView.backgroundColor = UIColor.gray
title.text = "Test"
title.textAlignment = .center
title.frame = CGRect(x: 0, y: 210, width: 200, height: 40)
title.textColor = .black
let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTapCollapse(_:)))
bgView.addGestureRecognizer(tap)
self.addSubview(bgView)
self.addSubview(title)
}
@objc func handleTapCollapse(_ sender: UITapGestureRecognizer) {
print("disabled")
// her I want to disable my collectionView
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
我想当我触摸我的 bgView 时禁用UICollectionView滚动。
我试过了didSelectItemAt,但是没有用。
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if indexPath.row == 1 {
animateCamerCell()
}
}
可能吗?如果不是这个问题的解决方案是什么?