|
@@ -0,0 +1,233 @@
|
|
|
+//
|
|
|
+// TSGennertatorSelectStyleVC.swift
|
|
|
+// AIEmoji
|
|
|
+//
|
|
|
+// Created by 100Years on 2025/4/27.
|
|
|
+//
|
|
|
+
|
|
|
+class TSGennertatorSelectStyleVC: TSBaseVC {
|
|
|
+
|
|
|
+ lazy var bottomView: UIView = {
|
|
|
+ let bottomView = UIView()
|
|
|
+ bottomView.backgroundColor = .popupColor
|
|
|
+ return bottomView
|
|
|
+ }()
|
|
|
+
|
|
|
+
|
|
|
+ lazy var xBtn: TSUIExpandedTouchButton = {
|
|
|
+ let xBtn = TSUIExpandedTouchButton()
|
|
|
+ xBtn.setUpButton(image: UIImage(named: "close_gray")) { [weak self] in
|
|
|
+ guard let self = self else { return }
|
|
|
+ self.dismiss(animated: true)
|
|
|
+ }
|
|
|
+ return xBtn
|
|
|
+ }()
|
|
|
+
|
|
|
+ var selectedValueBlock:((IndexPath,TSGenerateStyleModel)->Void)?
|
|
|
+
|
|
|
+ var dataArray: [TSGenerateStyleModel] = [TSGenerateStyleModel](){
|
|
|
+ didSet{
|
|
|
+ styleCollectionView.reloadData()
|
|
|
+ if dataArray.count > 0 {
|
|
|
+ self.styleCollectionView.selectItem(at: self.currentIndexPath, animated: false, scrollPosition: .centeredVertically)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ lazy var layout: UICollectionViewFlowLayout = {
|
|
|
+ let w = (k_ScreenWidth-32.0-30.0-2.0)/4.0
|
|
|
+ let layout = UICollectionViewFlowLayout()
|
|
|
+ layout.scrollDirection = .vertical
|
|
|
+ layout.itemSize = CGSize(width: w, height: 110)
|
|
|
+ layout.minimumInteritemSpacing = 0.0
|
|
|
+ layout.minimumLineSpacing = 10.0
|
|
|
+ layout.sectionInset = UIEdgeInsets(top: 0, left: 16, bottom: k_Height_safeAreaInsetsBottom(), 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(TSGennertatorSelectStyleCell.self, forCellWithReuseIdentifier: TSGennertatorSelectStyleCell.cellID)
|
|
|
+ if #available(iOS 11.0, *) {
|
|
|
+ collectionView.contentInsetAdjustmentBehavior = .never
|
|
|
+ }
|
|
|
+ return collectionView
|
|
|
+ }()
|
|
|
+
|
|
|
+ var currentIndexPath:IndexPath = IndexPath(item: 0, section: 0)
|
|
|
+
|
|
|
+ override func createView() {
|
|
|
+ self.view.backgroundColor = .clear
|
|
|
+ self.contentView.backgroundColor = .clear
|
|
|
+ setNavBarViewHidden(true)
|
|
|
+
|
|
|
+ contentView.addSubview(bottomView)
|
|
|
+ bottomView.snp.makeConstraints { make in
|
|
|
+ make.bottom.leading.trailing.bottom.equalTo(0)
|
|
|
+ make.top.equalTo(104+k_Nav_Height)
|
|
|
+ }
|
|
|
+ setContentView()
|
|
|
+
|
|
|
+ kDelayMainShort {
|
|
|
+ self.bottomView.cornersRound(radius: 20, corner: [.topLeft,.topRight])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func setContentView(){
|
|
|
+
|
|
|
+ let titleLabel = UILabel.createLabel(text: "Select Style".localized,font: .font(size: 16,weight: .medium),textColor: .white)
|
|
|
+ bottomView.addSubview(titleLabel)
|
|
|
+ titleLabel.snp.makeConstraints { make in
|
|
|
+ make.leading.equalTo(16)
|
|
|
+ make.top.equalTo(24)
|
|
|
+ }
|
|
|
+
|
|
|
+ bottomView.addSubview(xBtn)
|
|
|
+ xBtn.snp.makeConstraints { make in
|
|
|
+ make.top.equalTo(8)
|
|
|
+ make.trailing.equalTo(-8)
|
|
|
+ make.width.height.equalTo(24)
|
|
|
+ }
|
|
|
+
|
|
|
+ bottomView.addSubview(styleCollectionView)
|
|
|
+ styleCollectionView.snp.makeConstraints { make in
|
|
|
+ make.top.equalTo(56)
|
|
|
+ make.leading.trailing.equalTo(0)
|
|
|
+ make.bottom.equalTo(0)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override func dealThings() {
|
|
|
+ addPullDownClosePage()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension TSGennertatorSelectStyleVC: 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: TSGennertatorSelectStyleCell.cellID, for: indexPath)
|
|
|
+ if let cell = cell as? TSGennertatorSelectStyleCell,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
|
|
|
+ self.styleCollectionView.selectItem(at: self.currentIndexPath, animated: true, scrollPosition: .centeredVertically)
|
|
|
+ selectedValueBlock?(indexPath,model)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class TSGennertatorSelectStyleCell: TSBaseCollectionCell {
|
|
|
+
|
|
|
+ static let cellID = "TSGennertatorSelectStyleCell"
|
|
|
+
|
|
|
+ override var isSelected: Bool{
|
|
|
+ didSet{
|
|
|
+ boardImageView.isHidden = isSelected ? false : true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var itemModel:TSGenerateStyleModel = TSGenerateStyleModel(){
|
|
|
+ didSet{
|
|
|
+ imageView.image = UIImage(named: itemModel.imageName)
|
|
|
+
|
|
|
+ let hotImageNamed = getHotImageNamed(specialStyle: itemModel.specialStyle)
|
|
|
+ if hotImageNamed.count > 0 {
|
|
|
+ hotImageView.image = UIImage(named: hotImageNamed)
|
|
|
+ hotImageView.isHidden = false
|
|
|
+ }else{
|
|
|
+ hotImageView.isHidden = true
|
|
|
+ }
|
|
|
+ textLabel.text = itemModel.imageText.localized
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func getHotImageNamed(specialStyle:Int)->String{
|
|
|
+ if specialStyle == 1 {
|
|
|
+ return "ptp_style_hot"
|
|
|
+ }else if specialStyle == 2 {
|
|
|
+ return "ptp_style_new"
|
|
|
+ }else if specialStyle == 3 {
|
|
|
+ return "ptp_style_max"
|
|
|
+ }
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+
|
|
|
+ lazy var imageView: UIImageView = {
|
|
|
+ let imageView = UIImageView()
|
|
|
+ imageView.cornerRadius = kDesignScale*16.0
|
|
|
+ return imageView
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var hotImageView: UIImageView = {
|
|
|
+ let hotImageView = UIImageView.createImageView(imageName: "ptp_style_hot")
|
|
|
+ hotImageView.isHidden = true
|
|
|
+ return hotImageView
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var boardImageView: UIImageView = {
|
|
|
+ let boardImageView = UIImageView.createImageView(imageName: "ptp_selected_border")
|
|
|
+ boardImageView.isHidden = true
|
|
|
+ return boardImageView
|
|
|
+ }()
|
|
|
+
|
|
|
+
|
|
|
+ lazy var textLabel: UILabel = {
|
|
|
+ let textLabel = UILabel.createLabel(font: .font(size: 14),textColor: .white,textAlignment: .center,numberOfLines: 0)
|
|
|
+ textLabel.adjustsFontSizeToFitWidth = true
|
|
|
+ return textLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ override func creatUI() {
|
|
|
+ //cell 100*110
|
|
|
+
|
|
|
+
|
|
|
+ bgContentView.addSubview(boardImageView)
|
|
|
+ boardImageView.snp.makeConstraints { make in
|
|
|
+ make.top.centerX.equalToSuperview()
|
|
|
+ make.width.height.equalTo(contentView.width)
|
|
|
+ }
|
|
|
+
|
|
|
+ bgContentView.addSubview(imageView)
|
|
|
+ imageView.snp.makeConstraints { make in
|
|
|
+ make.top.equalTo(4*kDesignScale)
|
|
|
+ make.centerX.equalToSuperview()
|
|
|
+ make.width.height.equalTo(contentView.width-8*kDesignScale)
|
|
|
+ }
|
|
|
+
|
|
|
+ imageView.addSubview(hotImageView)
|
|
|
+ hotImageView.snp.makeConstraints { make in
|
|
|
+ make.leading.equalTo(0)
|
|
|
+ make.top.equalTo(0.0)
|
|
|
+ make.width.height.equalTo(36)
|
|
|
+ }
|
|
|
+
|
|
|
+ bgContentView.addSubview(textLabel)
|
|
|
+ textLabel.snp.makeConstraints { make in
|
|
|
+ make.top.equalTo(imageView.snp.bottom).offset(0)
|
|
|
+ make.leading.trailing.bottom.equalToSuperview()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|