58 lines
1.6 KiB
Swift
58 lines
1.6 KiB
Swift
|
|
//
|
|||
|
|
// IMContentBaseView.swift
|
|||
|
|
// Crush
|
|||
|
|
//
|
|||
|
|
// Created by Leon on 2025/8/18.
|
|||
|
|
//
|
|||
|
|
|
|||
|
|
import UIKit
|
|||
|
|
|
|||
|
|
protocol IMContentViewDelegate: NSObjectProtocol{
|
|||
|
|
func onTapAction(event: IMEventModel)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
class IMContentBaseView: UIView{
|
|||
|
|
var model: SessionBaseModel!
|
|||
|
|
var containerView: UIView = UIView()
|
|||
|
|
|
|||
|
|
weak var delegate: IMContentViewDelegate?
|
|||
|
|
|
|||
|
|
/// 刷新数据, 子类必须实现
|
|||
|
|
public func refreshModel(model: SessionBaseModel) {
|
|||
|
|
self.model = model
|
|||
|
|
// 更新约束
|
|||
|
|
let insets = model.config.contentInsets(model: model)
|
|||
|
|
self.containerView.snp.makeConstraints { make in
|
|||
|
|
make.leading.equalToSuperview().offset(insets.left)
|
|||
|
|
make.trailing.equalToSuperview().offset(-insets.right)
|
|||
|
|
make.top.equalToSuperview().offset(insets.top)
|
|||
|
|
make.bottom.equalToSuperview().offset(-insets.bottom)
|
|||
|
|
}
|
|||
|
|
self.layoutIfNeeded()
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
override init(frame: CGRect) {
|
|||
|
|
super.init(frame: frame)
|
|||
|
|
|
|||
|
|
self.addSubview(self.containerView)
|
|||
|
|
// self.containerView.layer.cornerRadius = 16 // 不用cell的maskLayer
|
|||
|
|
// 容器
|
|||
|
|
self.containerView.snp.makeConstraints { make in
|
|||
|
|
make.center.equalTo(self)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
let tap = UITapGestureRecognizer.init(target: self, action: #selector(cellTapAction))
|
|||
|
|
tap.cancelsTouchesInView = false
|
|||
|
|
self.addGestureRecognizer(tap)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
required init?(coder: NSCoder) {
|
|||
|
|
fatalError("init(coder:) has not been implemented")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@objc func cellTapAction() {
|
|||
|
|
// dlog("IMContentBaseView cellTapAction")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|