TSAIPhotoChildVC.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // TSAIPhotoChildVC.swift
  3. // AIRingtone
  4. //
  5. // Created by 100Years on 2025/3/4.
  6. //
  7. import JXSegmentedView
  8. import JXPagingView
  9. class TSAIPhotoChildVC: TSBaseVC {
  10. //联动滚动回调
  11. var listViewDidScrollCallback: ((UIScrollView) -> ())?
  12. var style:TSGennerateType
  13. lazy var vm: TSAIPhotoChildVM = {
  14. let vm = TSAIPhotoChildVM(style: style)
  15. return vm
  16. }()
  17. init(style: TSGennerateType) {
  18. self.style = style
  19. super.init()
  20. }
  21. @MainActor required init?(coder: NSCoder) {
  22. fatalError("init(coder:) has not been implemented")
  23. }
  24. lazy var collectionComponent: TSCollectionViewComponent = {
  25. let layout = UICollectionViewFlowLayout()
  26. let cp = TSCollectionViewComponent(frame: CGRect.zero, layout: layout, attributes: [ :])
  27. cp.collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 20, right: 0)
  28. cp.itemDidSelectedHandler = { [weak self] (object, indexPath) in
  29. guard let self = self else { return }
  30. if let sections = vm.colDataArray.safeObj(At: indexPath.section) as? TSColVVMSectionModel{
  31. var dataModelArray:[TSActionInfoModel] = []
  32. for itemModel in sections.items {
  33. if let model = itemModel.dataModel as? TSActionInfoModel {
  34. dataModelArray.append(model)
  35. }
  36. }
  37. switch style {
  38. case .poster:
  39. let browseVC = TSGeneralPosterBrowseVC()
  40. browseVC.dataModelArray = dataModelArray
  41. browseVC.currentIndex = indexPath.item
  42. kPresentModalVC(target: self, modelVC: browseVC,transitionStyle: .crossDissolve)
  43. case .photo:
  44. let browseVC = TSGeneralPhotoBrowseVC()
  45. browseVC.dataModelArray = dataModelArray
  46. browseVC.currentIndex = indexPath.item
  47. kPresentModalVC(target: self, modelVC: browseVC,transitionStyle: .crossDissolve)
  48. }
  49. }
  50. }
  51. return cp
  52. }()
  53. override func createView() {
  54. setNavBarViewHidden(true)
  55. contentView.addSubview(collectionComponent.collectionView)
  56. }
  57. func reloadView(){
  58. kExecuteOnMainThread {
  59. self.collectionComponent.clear()
  60. self.collectionComponent.reloadView(with:self.vm.colDataArray)
  61. }
  62. }
  63. override func viewDidLayoutSubviews() {
  64. super.viewDidLayoutSubviews()
  65. self.collectionComponent.collectionView.frame = self.view.bounds
  66. }
  67. override func dealThings() {
  68. reloadView()
  69. NotificationCenter.default.addObserver(forName: .kReloadUIData, object: nil, queue: nil) { notification in
  70. if let userInfo = notification.userInfo as? [String: TSGennerateType], let myEnum = userInfo["TSGennerateType"] {
  71. if myEnum == self.style {
  72. self.vm.setRecentData()
  73. self.reloadView()
  74. }
  75. }
  76. }
  77. }
  78. }
  79. extension TSAIPhotoChildVC: JXPagingViewListViewDelegate {
  80. func listScrollView() -> UIScrollView {
  81. collectionComponent.collectionView
  82. }
  83. func listViewDidScrollCallback(callback: @escaping (UIScrollView) -> ()) {
  84. listViewDidScrollCallback = callback
  85. }
  86. func listView() -> UIView { view }
  87. func listWillAppear() {
  88. }
  89. func listDidAppear() {
  90. // print("\(title ?? ""):\(#function)")
  91. }
  92. func listWillDisappear() {
  93. // print("\(title ?? ""):\(#function)")
  94. }
  95. func listDidDisappear() {
  96. // print("\(title ?? ""):\(#function)")
  97. }
  98. }