|
@@ -5,11 +5,9 @@
|
|
|
// Created by 100Years on 2024/12/20.
|
|
|
//
|
|
|
|
|
|
-
|
|
|
-import UIKit
|
|
|
import Kingfisher
|
|
|
+import UIKit
|
|
|
class TSTabBarController: UITabBarController {
|
|
|
-
|
|
|
// lazy var animatedImageView: AnimatedImageView = {
|
|
|
// let animatedImageView = AnimatedImageView()
|
|
|
// animatedImageView.autoPlayAnimatedImage = false
|
|
@@ -18,12 +16,12 @@ class TSTabBarController: UITabBarController {
|
|
|
// }
|
|
|
// return animatedImageView
|
|
|
// }()
|
|
|
-
|
|
|
+
|
|
|
private var viewControllerArray: [String] = []
|
|
|
private var titleArray: [String] = []
|
|
|
private var selectedImageArray: [String] = []
|
|
|
private var unselectedImageArray: [String] = []
|
|
|
-
|
|
|
+
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
|
createUI()
|
|
@@ -33,23 +31,22 @@ class TSTabBarController: UITabBarController {
|
|
|
}
|
|
|
|
|
|
@objc private func setUpData() {
|
|
|
-
|
|
|
- viewControllerArray = ["TSDiscoverVC","TSGenerateHistoryVC","TSSetingVC"]
|
|
|
- titleArray = ["Discover","Creations","Setting"]
|
|
|
+ viewControllerArray = ["TSDiscoverVC", "TSGenerateHistoryVC", "TSSetingVC"]
|
|
|
+ titleArray = ["Discover", "Creations", "Setting"]
|
|
|
selectedImageArray = [
|
|
|
"tabbar_select_pic",
|
|
|
"tabbar_select_history",
|
|
|
- "tabbar_select_setting"
|
|
|
+ "tabbar_select_setting",
|
|
|
]
|
|
|
unselectedImageArray = [
|
|
|
"tabbar_unSelect_pic",
|
|
|
"tabbar_unSelect_history",
|
|
|
- "tabbar_unSelect_setting"
|
|
|
+ "tabbar_unSelect_setting",
|
|
|
]
|
|
|
|
|
|
var tabArray: [UINavigationController] = []
|
|
|
|
|
|
- for i in 0..<viewControllerArray.count {
|
|
|
+ for i in 0 ..< viewControllerArray.count {
|
|
|
if let rootViewController = viewControllerArray[i].toInstance(of: UIViewController.self) {
|
|
|
let title = titleArray[i]
|
|
|
let nav = TSBaseNavigationC(rootViewController: rootViewController)
|
|
@@ -64,8 +61,7 @@ class TSTabBarController: UITabBarController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- self.viewControllers = tabArray
|
|
|
-
|
|
|
+ viewControllers = tabArray
|
|
|
}
|
|
|
|
|
|
private func createUI() {
|
|
@@ -73,20 +69,20 @@ class TSTabBarController: UITabBarController {
|
|
|
tabBar.isTranslucent = false
|
|
|
tabBar.backgroundColor = "#262626".uiColor
|
|
|
tabBar.backgroundImage = UIImage.colorFrom(color: tabBar.backgroundColor!, size: CGSize(width: k_ScreenWidth, height: k_TabBar_Height))
|
|
|
-
|
|
|
+
|
|
|
// 自定义 TabBarItem 字体颜色和选中颜色
|
|
|
- UITabBar.appearance().unselectedItemTintColor = .white.withAlphaComponent(0.4)// 未选中颜色
|
|
|
+ UITabBar.appearance().unselectedItemTintColor = .white.withAlphaComponent(0.4) // 未选中颜色
|
|
|
UITabBar.appearance().tintColor = UIColor.themeColor // 选中颜色
|
|
|
-
|
|
|
+
|
|
|
delegate = self
|
|
|
-
|
|
|
+
|
|
|
// Workaround to fix the tab bar position in iPad
|
|
|
if #available(iOS 18.0, *), UIDevice.current.userInterfaceIdiom == .pad {
|
|
|
tabBar.removeFromSuperview()
|
|
|
view.addSubview(tabBar)
|
|
|
traitOverrides.horizontalSizeClass = .compact
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
setupDoubleTapToScrollTop()
|
|
|
}
|
|
|
|
|
@@ -95,36 +91,35 @@ class TSTabBarController: UITabBarController {
|
|
|
tabBarItem.image = image?.withRenderingMode(.alwaysOriginal)
|
|
|
tabBarItem.title = title
|
|
|
tabBarItem.selectedImage = selectedImage?.withRenderingMode(.alwaysOriginal)
|
|
|
-
|
|
|
+
|
|
|
tabBarItem.setTitleTextAttributes([
|
|
|
- .font: UIFont.font(size: 12),
|
|
|
- ],for: .normal)
|
|
|
-
|
|
|
+ .font: UIFont.font(size: 12),
|
|
|
+ ], for: .normal)
|
|
|
+
|
|
|
tabBarItem.setTitleTextAttributes([
|
|
|
- .font: UIFont.font(size: 12),
|
|
|
- ], for: .selected)
|
|
|
-
|
|
|
+ .font: UIFont.font(size: 12),
|
|
|
+ ], for: .selected)
|
|
|
+
|
|
|
return tabBarItem
|
|
|
}
|
|
|
- func monitorEvent(){
|
|
|
-
|
|
|
- //后台生成后,跳转到历史页面
|
|
|
+
|
|
|
+ func monitorEvent() {
|
|
|
+ // 后台生成后,跳转到历史页面
|
|
|
NotificationCenter.default.addObserver(forName: .kAIComeInBackstage, object: nil, queue: .main) { _ in
|
|
|
if let nav = self.viewControllers?.safeObj(At: self.selectedIndex) as? UINavigationController {
|
|
|
nav.popToRootViewController(animated: false)
|
|
|
}
|
|
|
TSGenerateHistoryVC.showPosition()
|
|
|
}
|
|
|
-
|
|
|
- //升级弹窗
|
|
|
+
|
|
|
+ // 升级弹窗
|
|
|
refreshUpdateView()
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(refreshUpdateView), name: .kAppUpdateNotification, object: nil)
|
|
|
-
|
|
|
- //关闭订阅页面,弹出优惠订阅
|
|
|
+
|
|
|
+ // 关闭订阅页面,弹出优惠订阅
|
|
|
refreshPurchasePromotional()
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(refreshPurchasePromotional), name: .kCloseTSPurchaseVC, object: nil)
|
|
|
}
|
|
|
-
|
|
|
|
|
|
deinit {
|
|
|
debugPrint("TSTabBarController deinit")
|
|
@@ -132,51 +127,48 @@ class TSTabBarController: UITabBarController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
extension TSTabBarController {
|
|
|
- func changeSelectedIndex(index:Int){
|
|
|
- self.selectedIndex = index
|
|
|
+ func changeSelectedIndex(index: Int) {
|
|
|
+ selectedIndex = index
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-//升级弹窗
|
|
|
+// 升级弹窗
|
|
|
extension TSTabBarController {
|
|
|
@objc func refreshUpdateView() {
|
|
|
- if TSAppUpdateManager.isNeedUpdate,TSAppUpdateManager.isDisplayedUpdateAlert == false{
|
|
|
+ if TSAppUpdateManager.isNeedUpdate, TSAppUpdateManager.isDisplayedUpdateAlert == false {
|
|
|
kMainAfter(1.0) {
|
|
|
let updateAlertVC = TSAppUpdateAlertVC()
|
|
|
updateAlertVC.modalPresentationStyle = .overFullScreen
|
|
|
updateAlertVC.modalTransitionStyle = .crossDissolve
|
|
|
- self.present(updateAlertVC, animated: true,completion: {
|
|
|
+ self.present(updateAlertVC, animated: true, completion: {
|
|
|
TSAppUpdateManager.isDisplayedUpdateAlert = true
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-//关闭订阅页面,弹出优惠订阅
|
|
|
+// 关闭订阅页面,弹出优惠订阅
|
|
|
extension TSTabBarController {
|
|
|
@objc func refreshPurchasePromotional() {
|
|
|
- if TSPurchasePromotionalVC.showGift,kPurchaseCountDownTime.isNeedCheck == true{
|
|
|
+ if TSPurchasePromotionalVC.showGift, kPurchaseCountDownTime.isNeedCheck == true {
|
|
|
kMainAfter(0.3) {
|
|
|
let updateAlertVC = TSPurchasePromotionalVC(isAnimation: true)
|
|
|
updateAlertVC.modalPresentationStyle = .overFullScreen
|
|
|
updateAlertVC.modalTransitionStyle = .crossDissolve
|
|
|
- self.present(updateAlertVC, animated: true,completion: {
|
|
|
+ self.present(updateAlertVC, animated: true, completion: {
|
|
|
kPurchaseCountDownTime.isNeedCheck = false
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-//private let animatedIndex = 1
|
|
|
-//extension TSTabBarController {
|
|
|
+
|
|
|
+// private let animatedIndex = 1
|
|
|
+// extension TSTabBarController {
|
|
|
// func addAnimatedImageView(){
|
|
|
-//
|
|
|
+//
|
|
|
// let index = 1
|
|
|
// if let tabBarItems = tabBar.items,tabBarItems.count > index {
|
|
|
// let tabBarButtons = tabBar.subviews.filter({ $0.isKind(of: NSClassFromString("UITabBarButton")!) })
|
|
@@ -192,13 +184,13 @@ extension TSTabBarController {
|
|
|
// kDelayMainShort {
|
|
|
// self.animatedImageView.startAnimating()
|
|
|
// }
|
|
|
-//
|
|
|
+//
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
-//}
|
|
|
+// }
|
|
|
|
|
|
-extension TSTabBarController:UITabBarControllerDelegate {
|
|
|
+extension TSTabBarController: UITabBarControllerDelegate {
|
|
|
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
|
|
|
// if tabBarController.selectedIndex == animatedIndex {
|
|
|
// self.animatedImageView.isHidden = true
|
|
@@ -208,8 +200,6 @@ extension TSTabBarController:UITabBarControllerDelegate {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
protocol TSTabBarControllerProtocol {
|
|
|
func tabBarDoubleTap(_ tabbar: UITabBarController)
|
|
|
}
|
|
@@ -218,7 +208,7 @@ extension TSTabBarController {
|
|
|
func setupDoubleTapToScrollTop() {
|
|
|
let doubleTap = UITapGestureRecognizer(target: self, action: #selector(handleDoubleTap(_:)))
|
|
|
doubleTap.numberOfTapsRequired = 2
|
|
|
- doubleTap.delaysTouchesBegan = false // 默认是true,会延迟单击响应
|
|
|
+ doubleTap.delaysTouchesBegan = false // 默认是true,会延迟单击响应
|
|
|
doubleTap.delaysTouchesEnded = false
|
|
|
tabBar.addGestureRecognizer(doubleTap)
|
|
|
}
|
|
@@ -226,13 +216,12 @@ extension TSTabBarController {
|
|
|
@objc private func handleDoubleTap(_ gesture: UITapGestureRecognizer) {
|
|
|
guard gesture.state == .ended else { return }
|
|
|
guard let vc = selectedViewController else { return }
|
|
|
-
|
|
|
- if let vc = vc as? TSTabBarControllerProtocol{
|
|
|
+
|
|
|
+ if let vc = vc as? TSTabBarControllerProtocol {
|
|
|
vc.tabBarDoubleTap(self)
|
|
|
- }else if let nav = vc as? UINavigationController {
|
|
|
+ } else if let nav = vc as? UINavigationController {
|
|
|
if let topVC = nav.topViewController {
|
|
|
-
|
|
|
- if let vc = topVC as? TSTabBarControllerProtocol{
|
|
|
+ if let vc = topVC as? TSTabBarControllerProtocol {
|
|
|
vc.tabBarDoubleTap(self)
|
|
|
}
|
|
|
}
|