杨锴
2025-05-11 7453d2d0cef415b34323d1b91e6cfa4a6ba31178
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    //
    //  StudentRemarkTCell.swift
    //  WanPai
    //
    //  Created by 无故事王国 on 2023/6/27.
    //
 
import UIKit
import JQTools
import Lantern
 
class StudentRemarkTCell: UITableViewCell {
 
    var studentCommentModel:StudentCommentModel!{
        didSet{
            img_profile.sd_setImage(with: URL(string: studentCommentModel.headImg))
            label_name.text = studentCommentModel.stuName
            label_datetime.text = studentCommentModel.comTime
 
            label_content.attributedText = AttributedStringbuilder.build().add(string: studentCommentModel.contents, withFont: UIFont.systemFont(ofSize: 12), withColor: UIColor.black.withAlphaComponent(0.8), lineSpace: 5).mutableAttributedString
            let count = studentCommentModel.imgs.count
            cons_imgHei.constant = ceil(Double(count) / 3) * cellW + floor(Double(count) / 3) * 9
            collectionView.reloadData()
        }
    }
 
    private let cellW:Double = (JQ_ScreenW - 55.0) / 3.0
    @IBOutlet weak var collectionView: UICollectionView!
    @IBOutlet weak var img_profile: UIImageView!
    @IBOutlet weak var label_name: UILabel!
    @IBOutlet weak var label_datetime: UILabel!
    @IBOutlet weak var label_content: UILabel!
    @IBOutlet weak var cons_imgHei: NSLayoutConstraint!
 
    override func awakeFromNib() {
        super.awakeFromNib()
        selectionStyle = .none
 
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.isScrollEnabled = false
        collectionView.register(UINib(nibName: "CommonSingleImgCCell", bundle: nil), forCellWithReuseIdentifier: "_CommonSingleImgCCell")
        cons_imgHei.constant = 0
    }
}
 
extension StudentRemarkTCell:UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_CommonSingleImgCCell", for: indexPath) as! CommonSingleImgCCell
        cell.img.backgroundColor = .gray.withAlphaComponent(0.1)
        let imgUrl = studentCommentModel.imgs[indexPath.row]
        cell.img.sd_setImage(with: URL(string: imgUrl))
        return cell
    }
 
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return studentCommentModel.imgs.count
    }
}
 
extension StudentRemarkTCell:UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let lantern = Lantern()
        lantern.numberOfItems = {[weak self] in
            return self?.studentCommentModel.imgs.count ?? 0
        }
 
        lantern.cellClassAtIndex = { _ in
            LanternImageCell.self
        }
 
        lantern.transitionAnimator = LanternZoomAnimator(previousView: { index -> UIView? in
 
            let cell = collectionView.cellForItem(at: IndexPath(item: index, section: indexPath.section)) as! CommonSingleImgCCell
            return cell.img
        })
 
 
            // UIPageIndicator样式的页码指示器
        lantern.pageIndicator = LanternDefaultPageIndicator()
 
        lantern.pageIndex = indexPath.item
 
        lantern.reloadCellAtIndex = { context in
            let lanternCell = context.cell as? LanternImageCell
            let cell = collectionView.cellForItem(at: IndexPath(item:context.index, section: indexPath.section)) as! CommonSingleImgCCell
            lanternCell?.imageView.image = cell.img.image
        }
            //不要使用push
        lantern.show()
    }
 
}
 
extension StudentRemarkTCell:UICollectionViewDelegateFlowLayout{
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: cellW, height: cellW)
    }
 
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 9
    }
 
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 9
    }
}