123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- //
- // TSAIPhotoChildVC.swift
- // AIRingtone
- //
- // Created by 100Years on 2025/3/4.
- //
- import JXSegmentedView
- import JXPagingView
- class TSAIPhotoChildVC: TSBaseVC {
- //联动滚动回调
- var listViewDidScrollCallback: ((UIScrollView) -> ())?
- var style:TSGennerateType
-
- lazy var vm: TSAIPhotoChildVM = {
- let vm = TSAIPhotoChildVM(style: style)
- return vm
- }()
-
- init(style: TSGennerateType) {
- self.style = style
- super.init()
- }
-
- @MainActor required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
-
- lazy var collectionComponent: TSCollectionViewComponent = {
- let layout = UICollectionViewFlowLayout()
- let cp = TSCollectionViewComponent(frame: CGRect.zero, layout: layout, attributes: [ :])
- cp.collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 20, right: 0)
- cp.itemDidSelectedHandler = { [weak self] (object, indexPath) in
- guard let self = self else { return }
-
- if let sections = vm.colDataArray.safeObj(At: indexPath.section) as? TSColVVMSectionModel{
-
- if let itemModel = sections.items.safeObj(At: indexPath.item) ,
- let model = itemModel.dataModel as? TSActionInfoModel,
- model.actionStatus != .success{
- return
- }
- var dataModelArray:[TSActionInfoModel] = []
- for itemModel in sections.items {
- if let model = itemModel.dataModel as? TSActionInfoModel {
- dataModelArray.append(model)
- }
- }
- switch style {
- case .poster:
- let browseVC = TSGeneralPosterBrowseVC()
- browseVC.dataModelArray = dataModelArray
- browseVC.currentIndex = indexPath.item
- kPresentModalVC(target: self, modelVC: browseVC,transitionStyle: .crossDissolve)
- case .photo:
- let browseVC = TSGeneralPhotoBrowseVC()
- browseVC.dataModelArray = dataModelArray
- browseVC.currentIndex = indexPath.item
- kPresentModalVC(target: self, modelVC: browseVC,transitionStyle: .crossDissolve)
- }
- }
- }
- return cp
- }()
-
- override func createView() {
- setNavBarViewHidden(true)
- contentView.addSubview(collectionComponent.collectionView)
- }
-
- func reloadView(){
- kExecuteOnMainThread {
- self.collectionComponent.clear()
- self.collectionComponent.reloadView(with:self.vm.colDataArray)
- }
- }
- override func viewDidLayoutSubviews() {
- super.viewDidLayoutSubviews()
- self.collectionComponent.collectionView.frame = self.view.bounds
- }
-
- override func dealThings() {
- reloadView()
- NotificationCenter.default.addObserver(forName: .kReloadUIData, object: nil, queue: nil) { [weak self] notification in
- guard let self = self else { return }
- if let userInfo = notification.userInfo as? [String: TSGennerateType], let myEnum = userInfo["TSGennerateType"] {
- if myEnum == self.style {
- self.vm.setRecentData()
- self.reloadView()
- }
- }
- }
-
- NotificationCenter.default.addObserver(forName: self.style == .poster ? .kGeneratePosterOperationChanged : .kGeneratePhotoOperationChanged , object: nil, queue: nil) { notification in
- if let userInfo = notification.userInfo as? [String: Any], let uuid = userInfo["uuid"] as? String,let state = userInfo["state"] as? TSProgressState {
- dePrint("TSBaseOperation stateDatauPblished 收到 = \(state)")
- switch state {
- case .start, .success(_),.failed(_),.none:
- self.vm.setRecentData()
- self.reloadView()
- default:break
- }
- }
- }
- }
- }
- extension TSAIPhotoChildVC: JXPagingViewListViewDelegate {
-
- func listScrollView() -> UIScrollView {
- collectionComponent.collectionView
- }
- func listViewDidScrollCallback(callback: @escaping (UIScrollView) -> ()) {
- listViewDidScrollCallback = callback
- }
- func listView() -> UIView { view }
-
- func listWillAppear() {
-
- }
- func listDidAppear() {
- // print("\(title ?? ""):\(#function)")
- }
- func listWillDisappear() {
- // print("\(title ?? ""):\(#function)")
- }
- func listDidDisappear() {
- // print("\(title ?? ""):\(#function)")
- }
- }
|