|
@@ -0,0 +1,159 @@
|
|
|
+//
|
|
|
+// TSTTPRatioView.swift
|
|
|
+// AIEmoji
|
|
|
+//
|
|
|
+// Created by 100Years on 2025/4/29.
|
|
|
+//
|
|
|
+
|
|
|
+class TSTTPRatioView:TSBaseView {
|
|
|
+
|
|
|
+ var selectedValueBlock:((TSGenerateStyleModel)->Void)?
|
|
|
+
|
|
|
+ var dataArray: [TSGenerateStyleModel] = [TSGenerateStyleModel](){
|
|
|
+ didSet{
|
|
|
+ styleCollectionView.reloadData()
|
|
|
+ if dataArray.count > 0 {
|
|
|
+ self.styleCollectionView.selectItem(at: self.currentIndexPath, animated: false, scrollPosition: .centeredHorizontally)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ lazy var layout: UICollectionViewFlowLayout = {
|
|
|
+ let layout = UICollectionViewFlowLayout()
|
|
|
+ layout.scrollDirection = .horizontal
|
|
|
+ layout.itemSize = CGSize(width: 68, height: 80)
|
|
|
+ layout.minimumInteritemSpacing = 12.0
|
|
|
+ layout.minimumLineSpacing = 0.0
|
|
|
+ layout.sectionInset = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
|
|
|
+ return layout
|
|
|
+ }()
|
|
|
+
|
|
|
+
|
|
|
+ lazy var styleCollectionView: UICollectionView = {
|
|
|
+ let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
|
|
|
+ collectionView.delegate = self
|
|
|
+ collectionView.dataSource = self
|
|
|
+ collectionView.showsVerticalScrollIndicator = false
|
|
|
+ collectionView.showsHorizontalScrollIndicator = false
|
|
|
+ collectionView.backgroundColor = .clear
|
|
|
+ collectionView.register(TSTTPRatioViewCell.self, forCellWithReuseIdentifier: TSTTPRatioViewCell.cellID)
|
|
|
+ if #available(iOS 11.0, *) {
|
|
|
+ collectionView.contentInsetAdjustmentBehavior = .never
|
|
|
+ }
|
|
|
+ return collectionView
|
|
|
+ }()
|
|
|
+
|
|
|
+ var currentIndexPath:IndexPath = IndexPath(item: 0, section: 0)
|
|
|
+
|
|
|
+
|
|
|
+ lazy var titleView: TSTitleView = {
|
|
|
+ let titleView = TSTitleView()
|
|
|
+ titleView.titleLab.text = "Ratio".localized
|
|
|
+ return titleView
|
|
|
+ }()
|
|
|
+
|
|
|
+
|
|
|
+ override func creatUI() {
|
|
|
+
|
|
|
+ let titleViewH = titleView.viewH
|
|
|
+ contentView.addSubview(titleView)
|
|
|
+ titleView.snp.makeConstraints { make in
|
|
|
+ make.top.equalTo(0)
|
|
|
+ make.leading.trailing.equalTo(0)
|
|
|
+ make.height.equalTo(titleViewH)
|
|
|
+ }
|
|
|
+
|
|
|
+ currentIndexPath = IndexPath(item: 0, section: 0)
|
|
|
+ contentView.addSubview(styleCollectionView)
|
|
|
+ styleCollectionView.snp.makeConstraints { make in
|
|
|
+ make.top.equalTo(titleView.snp.bottom)
|
|
|
+ make.leading.trailing.equalTo(0)
|
|
|
+ make.height.equalTo(110)
|
|
|
+ make.bottom.equalTo(0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func unCheck(){
|
|
|
+ styleCollectionView.deselectItem(at: currentIndexPath, animated: true)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+extension TSTTPRatioView: UICollectionViewDataSource ,UICollectionViewDelegate {
|
|
|
+
|
|
|
+ public func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
|
+ return 1
|
|
|
+ }
|
|
|
+
|
|
|
+ public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
+ return dataArray.count
|
|
|
+ }
|
|
|
+
|
|
|
+ public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
+
|
|
|
+ let cell = collectionView.dequeueReusableCell(withReuseIdentifier: TSTTPRatioViewCell.cellID, for: indexPath)
|
|
|
+ if let cell = cell as? TSTTPRatioViewCell,let itemModel = dataArray.safeObj(At: indexPath.item){
|
|
|
+ cell.itemModel = itemModel
|
|
|
+ }
|
|
|
+ return cell
|
|
|
+ }
|
|
|
+
|
|
|
+ public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
+ if let model = dataArray.safeObj(At: indexPath.item){
|
|
|
+ currentIndexPath = indexPath
|
|
|
+ selectedValueBlock?(model)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class TSTTPRatioViewCell: TSBaseCollectionCell {
|
|
|
+
|
|
|
+ static let cellID = "TSTTPRatioViewCell"
|
|
|
+
|
|
|
+ override var isSelected: Bool{
|
|
|
+ didSet{
|
|
|
+ boardImageView.isHidden = isSelected ? false : true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var itemModel:TSGenerateStyleModel = TSGenerateStyleModel(){
|
|
|
+ didSet{
|
|
|
+ imageView.image = UIImage(named: itemModel.imageName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ lazy var boardImageView: UIImageView = {
|
|
|
+ let boardImageView = UIImageView.createImageView(imageName: "ttp_selected_border")
|
|
|
+ boardImageView.isHidden = true
|
|
|
+ return boardImageView
|
|
|
+ }()
|
|
|
+
|
|
|
+
|
|
|
+ lazy var imageView: UIImageView = {
|
|
|
+ let imageView = UIImageView()
|
|
|
+ imageView.cornerRadius = 40.0
|
|
|
+ return imageView
|
|
|
+ }()
|
|
|
+
|
|
|
+
|
|
|
+ override func creatUI() {
|
|
|
+ //cell 100*110
|
|
|
+
|
|
|
+ bgContentView.addSubview(imageView)
|
|
|
+ imageView.snp.makeConstraints { make in
|
|
|
+ make.top.equalTo(0)
|
|
|
+ make.centerX.equalToSuperview()
|
|
|
+ make.width.height.equalTo(80)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ imageView.addSubview(boardImageView)
|
|
|
+ boardImageView.snp.makeConstraints { make in
|
|
|
+ make.top.bottom.leading.trailing.equalTo(0)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|