123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- //
- // TSGennertatorSelectStyleVC.swift
- // AIEmoji
- //
- // Created by 100Years on 2025/4/27.
- //
- class TSGennertatorSelectStyleVC: TSBaseVC {
- enum Style {
- case ptp
- case ttp
- }
-
- 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_clear")) { [weak self] in
- guard let self = self else { return }
- self.dismiss(animated: true)
- }
- return xBtn
- }()
-
- var style:Style = .ptp
- 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.itemSize = CGSize(width: w, height: 108)
-
- layout.scrollDirection = .vertical
- layout.minimumInteritemSpacing = 0.0
- layout.minimumLineSpacing = 4.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])
- }
-
-
-
- let topView = UIView()
- topView.backgroundColor = .clear
- contentView.addSubview(topView)
- topView.snp.makeConstraints { make in
- make.top.leading.trailing.equalTo(0)
- make.bottom.equalTo(bottomView.snp.top)
- }
- topView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(clickView)))
- }
-
- @objc func clickView(){
- self.dismiss(animated: true)
- }
- 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() {
- }
- }
- 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.style = style
- 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
- textLabel.textColor = isSelected ? .themeColor : .white.withAlphaComponent(0.8)
- }
- }
- var style:TSGennertatorSelectStyleVC.Style = .ptp{
-
- didSet{
- switch style {
- case .ptp:
- boardImageView.cornerRadius = 16
- let w = 78
- boardImageView.snp.updateConstraints { make in
- make.width.height.equalTo(w)
- }
- imageView.snp.updateConstraints { make in
- make.top.equalTo(4)
- make.width.height.equalTo(w-8)
- }
- case .ttp:
- boardImageView.cornerRadius = 34.0
- let w = 68.0
- boardImageView.snp.updateConstraints { make in
- make.width.height.equalTo(w)
- }
- imageView.snp.updateConstraints { make in
- make.top.equalTo(4)
- make.width.height.equalTo(w-8)
- }
- }
- }
- }
- var itemModel:TSGenerateStyleModel = TSGenerateStyleModel(){
- didSet{
- imageView.image = UIImage(named: itemModel.imageName)
-
- let hotImageNamed = getSpecialStyleImageNamed(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 getSpecialStyleImageNamed(specialStyle:Int)->String{
- switch style {
- case .ptp:
- if specialStyle == 1 {
- return "ptp_style_hot"
- }else if specialStyle == 2 {
- return "ptp_style_new"
- }else if specialStyle == 3 {
- return "ptp_style_max"
- }
- case .ttp:
- if specialStyle == 1 {
- return "ttp_style_hot"
- }else if specialStyle == 2 {
- return "ptp_style_new"
- }else if specialStyle == 3 {
- return "ptp_style_max"
- }
- }
- return ""
- }
-
- lazy var boardImageView: UIImageView = {
- let boardImageView = UIImageView()
- boardImageView.cornerRadius = 16
- boardImageView.isHidden = true
- return boardImageView
- }()
- lazy var imageView: UIImageView = {
- let imageView = UIImageView()
- imageView.cornerRadius = 12
- return imageView
- }()
-
- lazy var hotImageView: UIImageView = {
- let hotImageView = UIImageView.createImageView(imageName: "ptp_style_hot")
- hotImageView.isHidden = true
- return hotImageView
- }()
-
- lazy var textLabel: UILabel = {
- let textLabel = UILabel.createLabel(font: .font(size: 12),textColor: .white.withAlphaComponent(0.8),textAlignment: .center,numberOfLines: 2)
- return textLabel
- }()
-
- override func creatUI() {
- // let w = contentView.width
- let w = 78
-
- bgContentView.addSubview(boardImageView)
- boardImageView.snp.makeConstraints { make in
- make.top.centerX.equalToSuperview()
- make.width.height.equalTo(w)
- }
-
- bgContentView.addSubview(imageView)
- imageView.snp.makeConstraints { make in
- make.top.equalTo(4)
- make.centerX.equalToSuperview()
- make.width.height.equalTo(w-8)
- }
-
- 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(2)
- make.leading.trailing.bottom.equalToSuperview()
- }
-
- boardImageView.setNeedsLayout()
- DispatchQueue.main.async {
- self.boardImageView.addGradientBorder(colors: ["#FA794F".uiColor,"#F8C32A".uiColor,"#FEFBF4".uiColor],width: 1.5,startPoint: CGPoint(x: 0, y: 1),endPoint: CGPoint(x: 1, y: 0))
- }
- }
-
- }
|