swift UITableViewCell内嵌套collectionView,如何实现高亮状态

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容