UITableViewCell:
cell?.longTapCallBack = {
[weak self] in
cell?.highLightView.backgroundColor = .gray.withAlphaComponent(0.15)
}
cell?.endTapCallBack = {
[weak self] in
UIView.animate(withDuration: 0.15) {
cell?.highLightView.backgroundColor = .clear
}
}
//点击选中的高亮状态
func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
let cellContent = tableView.cellForRow(at: indexPath) as! ZZPaperPlaneExpressionViewCell
cellContent.highLightView.backgroundColor = .gray.withAlphaComponent(0.15)
}
func tableView(_ tableView: UITableView, didUnhighlightRowAt indexPath: IndexPath) {
let cellContent = tableView.cellForRow(at: indexPath) as! ZZPaperPlaneExpressionViewCell
cellContent.highLightView.backgroundColor = .clear
}
嵌套在cell中的 collectionView:
let longTap = UILongPressGestureRecognizer(target: self, action: #selector(longClick))
longTap.minimumPressDuration = 0.2
collectionView.addGestureRecognizer(longTap)
collectionView.allowsSelection = false
长按手势
@objc func longClick(gesture: UILongPressGestureRecognizer) {
if self.longTapCallBack != nil {
self.longTapCallBack!()
}
switch gesture.state {
case .ended:
if self.endTapCallBack != nil {
self.endTapCallBack!()
}
default:
break
}
}
嵌套在cell 中的 highLightView:
let highLightView = UIView()
self.highLightView = highLightView
highLightView.backgroundColor = .clear
highLightView.layer.cornerRadius = 12
highLightView.layer.masksToBounds = true
self.whiteBgView.addSubview(highLightView)
highLightView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
highLightView.isUserInteractionEnabled = true