|
@@ -7,6 +7,9 @@
|
|
|
//
|
|
|
|
|
|
import UIKit
|
|
|
+import Lottie
|
|
|
+import ESTabBarController_swift
|
|
|
+
|
|
|
/*
|
|
|
class BaseTabbarViewController: UITabBarController {
|
|
|
|
|
@@ -36,26 +39,20 @@ class BaseTabbarViewController: UITabBarController {
|
|
|
}
|
|
|
|
|
|
func setViewControllers() {
|
|
|
- tabBarItemStyle(vc: v1, normalImg: "tabbar_home", selectorImg: "tabbar_home_pre", title: "社区")
|
|
|
-
|
|
|
- tabBarItemStyle(vc: v2, normalImg: "tabbar_shopping", selectorImg: "tabbar_shopping_pre", title: "商城")
|
|
|
-
|
|
|
- tabBarItemStyle(vc: v3, normalImg: "tabbar_publish", selectorImg: "tabbar_publish", title: "")
|
|
|
+ v1.tabBarItem = ESTabBarItem.init(BaseLottieAnimateContentView(jsonStr: "communityModuleTabbar"), title: "社区", image: UIImage(named: "tabbar_home")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal), selectedImage: nil)
|
|
|
+ v2.tabBarItem = ESTabBarItem.init(BaseLottieAnimateContentView(jsonStr: "shoppingMallModuleTabbar"), title: "商城", image: UIImage(named: "tabbar_shopping"), selectedImage: nil)
|
|
|
+ v3.tabBarItem = UITabBarItem(title: nil, image: UIImage(named: "tabbar_publish")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal), selectedImage: UIImage(named: "tabbar_publish")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal))
|
|
|
v3.tabBarItem.imageInsets = UIEdgeInsets(top: 4, left: 0, bottom: -4, right: 0);
|
|
|
+ v4.tabBarItem = ESTabBarItem.init(BaseLottieAnimateContentView(jsonStr: "messageModuleTabbar"), title: "消息", image: UIImage(named: "tabbar_massage"), selectedImage: nil)
|
|
|
+ v5.tabBarItem = ESTabBarItem.init(BaseLottieAnimateContentView(jsonStr: "MineModuleTabbar"), title: "我的", image: UIImage(named: "tabbar_my"), selectedImage: nil)
|
|
|
|
|
|
- tabBarItemStyle(vc: v4, normalImg: "tabbar_massage", selectorImg: "tabbar_massage_pre", title: "消息")
|
|
|
+ let n1 = BaseNavigationViewController.init(rootViewController: v1)
|
|
|
+ let n2 = BaseNavigationViewController.init(rootViewController: v2)
|
|
|
+ let n3 = BaseNavigationViewController.init(rootViewController: v3)
|
|
|
+ let n4 = BaseNavigationViewController.init(rootViewController: v4)
|
|
|
+ let n5 = BaseNavigationViewController.init(rootViewController: v5)
|
|
|
|
|
|
- tabBarItemStyle(vc: v5, normalImg: "tabbar_my", selectorImg: "tabbar_my_pre", title: "我的")
|
|
|
- }
|
|
|
-
|
|
|
- func tabBarItemStyle(vc : BaseViewController, normalImg : String, selectorImg : String, title : String){
|
|
|
- vc.tabBarItem.title = title
|
|
|
- vc.tabBarItem.image = UIImage.init(named: normalImg)?.withRenderingMode(.alwaysOriginal)
|
|
|
- vc.tabBarItem.selectedImage = UIImage.init(named: selectorImg)?.withRenderingMode(.alwaysOriginal)
|
|
|
-
|
|
|
- vc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor:k333333Color], for: UIControl.State.selected)
|
|
|
- vc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor:k666666Color], for: UIControl.State.normal)
|
|
|
- self.addChild(BaseNavigationViewController.init(rootViewController: vc))
|
|
|
+ self.viewControllers = [n1, n2, n3, n4, n5]
|
|
|
}
|
|
|
|
|
|
func setTag() {
|
|
@@ -77,120 +74,135 @@ class BaseTabbarViewController: UITabBarController {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ */
|
|
|
|
|
|
-extension BaseTabbarViewController : UITabBarControllerDelegate {
|
|
|
-
|
|
|
- func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
|
|
|
-
|
|
|
- if viewController.tabBarItem.tag == 2 {
|
|
|
- return false
|
|
|
- }else{
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
|
|
|
-
|
|
|
- if item.tag == 2 {
|
|
|
- let pickVc = PublishViewController()
|
|
|
- let nav = BaseNavigationViewController.init(rootViewController: pickVc)
|
|
|
- self.present(nav, animated: true, completion: nil)
|
|
|
- }else {
|
|
|
- if item.tag == self.lastClickTag && item.tag == 0 {
|
|
|
-
|
|
|
- if communityModuleTopType == .communityModuleFollowTop {
|
|
|
- NotificationCenter.default.post(name: NSNotification.Name("CommunityModuleFollowTop"), object: nil)
|
|
|
-
|
|
|
- }
|
|
|
- if communityModuleTopType == .communityModuleRecommendTop {
|
|
|
- NotificationCenter.default.post(name: NSNotification.Name("CommunityModuleRecommendTop"), object: nil)
|
|
|
-
|
|
|
- }
|
|
|
- if communityModuleTopType == .communityModulePlanetTop {
|
|
|
- NotificationCenter.default.post(name: NSNotification.Name("CommunityModulePlanetTop"), object: nil)
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- if item.tag == self.lastClickTag && item.tag == 1 {
|
|
|
- NotificationCenter.default.post(name: NSNotification.Name("ShoppingMallModuleTop"), object: nil)
|
|
|
-// NotificationCenter.default.post(name: NSNotification.Name("RedemptionAreaModuleTop"), object: nil)
|
|
|
-
|
|
|
- }
|
|
|
- if item.tag == self.lastClickTag && item.tag == 3 {
|
|
|
- NotificationCenter.default.post(name: NSNotification.Name("MessageModuleTop"), object: nil)
|
|
|
-
|
|
|
- }
|
|
|
- if item.tag == self.lastClickTag && item.tag == 4 {
|
|
|
- NotificationCenter.default.post(name: NSNotification.Name("MineModuleTop"), object: nil)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- self.lastClickTag = item.tag
|
|
|
-
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-*/
|
|
|
|
|
|
-import ESTabBarController_swift
|
|
|
+class BaseTabbarViewController: ESTabBarController {
|
|
|
|
|
|
-class BaseTabbarViewController : ESTabBarController {
|
|
|
-
|
|
|
static let shared : BaseTabbarViewController = BaseTabbarViewController()
|
|
|
|
|
|
- var lastClickTag : Int?
|
|
|
-
|
|
|
/// 社区
|
|
|
let v1 = CommunityViewController()
|
|
|
/// 商城
|
|
|
let v2 = ShoppingMallViewController()
|
|
|
- /// 兑换专区
|
|
|
- // let v2 = RedemptionAreaViewController()
|
|
|
/// 发布
|
|
|
- let v3 = BaseViewController()
|
|
|
+ let v3 = UIViewController()
|
|
|
/// 消息
|
|
|
let v4 = MessageMainViewController()
|
|
|
/// 我的
|
|
|
let v5 = UserPersonalCenterViewController()
|
|
|
+
|
|
|
+ /// 社区
|
|
|
+ let lottieAnimateContentView1 = BaseLottieAnimateContentView(jsonStr: "communityModuleTabbar")
|
|
|
+
|
|
|
+ /// 商城
|
|
|
+ let lottieAnimateContentView2 = BaseLottieAnimateContentView(jsonStr: "shoppingMallModuleTabbar")
|
|
|
+
|
|
|
+ /// 消息
|
|
|
+ let lottieAnimateContentView4 = BaseLottieAnimateContentView(jsonStr: "messageModuleTabbar")
|
|
|
+
|
|
|
+ /// 我的
|
|
|
+ let lottieAnimateContentView5 = BaseLottieAnimateContentView(jsonStr: "MineModuleTabbar")
|
|
|
+
|
|
|
+ var lastIndex : Int = 0
|
|
|
|
|
|
- override func viewDidLoad() {
|
|
|
-
|
|
|
- self.tabBar.shadowImage = UIImage(named: "tab_top_line")
|
|
|
- self.delegate = self as? UITabBarControllerDelegate
|
|
|
-
|
|
|
- self.shouldHijackHandler = {
|
|
|
- tabbarController, viewController, index in
|
|
|
+ func tabBarViewController() -> ESTabBarController {
|
|
|
+ let tabBarViewController = ESTabBarController()
|
|
|
+
|
|
|
+ tabBarViewController.tabBar.shadowImage = UIImage(named: "tab_top_line")
|
|
|
+ tabBarViewController.shouldHijackHandler = {
|
|
|
+ [weak self] (tabbarController, viewController, index) in
|
|
|
if index == 2 {
|
|
|
+ self?.lastIndex = index
|
|
|
return true
|
|
|
+ }else {
|
|
|
+ self?.reloadTabbar(index:index)
|
|
|
+ self?.lastIndex = index
|
|
|
+ return false
|
|
|
}
|
|
|
- return false
|
|
|
}
|
|
|
- self.didHijackHandler = {
|
|
|
- [weak self] tabbarController, viewController, index in
|
|
|
+
|
|
|
+ tabBarViewController.didHijackHandler = {
|
|
|
+ tabbarController, viewController, index in
|
|
|
let pickVc = PublishViewController()
|
|
|
let nav = BaseNavigationViewController.init(rootViewController: pickVc)
|
|
|
- self?.present(nav, animated: true, completion: nil)
|
|
|
+ tabbarController.present(nav, animated: true, completion: nil)
|
|
|
}
|
|
|
-
|
|
|
- v1.tabBarItem = ESTabBarItem.init(BaseLottieAnimateContentView(), title: "社区", image: UIImage(named: "tabbar_home"), selectedImage: UIImage(named: "tabbar_home_pre"))
|
|
|
- v2.tabBarItem = ESTabBarItem.init(BaseLottieAnimateContentView(), title: "商城", image: UIImage(named: "tabbar_shopping"), selectedImage: UIImage(named: "tabbar_shopping_pre"))
|
|
|
- v3.tabBarItem = ESTabBarItem.init(BaseLottieAnimateContentView(), title: nil, image: UIImage(named: "tabbar_publish"), selectedImage: UIImage(named: "tabbar_publish"))
|
|
|
+
|
|
|
+ v1.tabBarItem = ESTabBarItem.init(lottieAnimateContentView1, title: "社区", image: UIImage(named: "tabbar_home")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal), selectedImage: nil)
|
|
|
+ v2.tabBarItem = ESTabBarItem.init(lottieAnimateContentView2, title: "商城", image: UIImage(named: "tabbar_shopping"), selectedImage: nil)
|
|
|
+ v3.tabBarItem = UITabBarItem(title: nil, image: UIImage(named: "tabbar_publish")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal), selectedImage: UIImage(named: "tabbar_publish")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal))
|
|
|
v3.tabBarItem.imageInsets = UIEdgeInsets(top: 4, left: 0, bottom: -4, right: 0);
|
|
|
+ v4.tabBarItem = ESTabBarItem.init(lottieAnimateContentView4, title: "消息", image: UIImage(named: "tabbar_massage"), selectedImage: nil)
|
|
|
+ v5.tabBarItem = ESTabBarItem.init(lottieAnimateContentView5, title: "我的", image: UIImage(named: "tabbar_my"), selectedImage: nil)
|
|
|
|
|
|
- v4.tabBarItem = ESTabBarItem.init(BaseLottieAnimateContentView(), title: "消息", image: UIImage(named: "tabbar_massage"), selectedImage: UIImage(named: "tabbar_massage_pre"))
|
|
|
- v5.tabBarItem = ESTabBarItem.init(BaseLottieAnimateContentView(), title: "我的", image: UIImage(named: "tabbar_my"), selectedImage: UIImage(named: "tabbar_my_pre"))
|
|
|
-
|
|
|
- addNavigationVC(vc: v1)
|
|
|
- addNavigationVC(vc: v2)
|
|
|
- addNavigationVC(vc: v3)
|
|
|
- addNavigationVC(vc: v4)
|
|
|
- addNavigationVC(vc: v5)
|
|
|
+ let n1 = BaseNavigationViewController.init(rootViewController: v1)
|
|
|
+ let n2 = BaseNavigationViewController.init(rootViewController: v2)
|
|
|
+ let n3 = BaseNavigationViewController.init(rootViewController: v3)
|
|
|
+ let n4 = BaseNavigationViewController.init(rootViewController: v4)
|
|
|
+ let n5 = BaseNavigationViewController.init(rootViewController: v5)
|
|
|
+
|
|
|
+ tabBarViewController.viewControllers = [n1, n2, n3, n4, n5]
|
|
|
+ //将要进入前台的时候
|
|
|
+ setBadge()
|
|
|
+ NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: OperationQueue.main, using: {
|
|
|
+ [weak self] (notification) in
|
|
|
+ self?.setBadge()
|
|
|
+ })
|
|
|
+ return tabBarViewController
|
|
|
}
|
|
|
|
|
|
- func addNavigationVC(vc:UIViewController) {
|
|
|
- self.addChild(BaseNavigationViewController.init(rootViewController: vc))
|
|
|
+ // 设置Badge
|
|
|
+ func setBadge() {
|
|
|
+ if UpdateVersionModel.shared.object()?.upGradeModelType == .update || UpdateVersionModel.shared.object()?.upGradeModelType == .strongUpdate {
|
|
|
+
|
|
|
+ let tabBarItem = v5.tabBarItem as? ESTabBarItem
|
|
|
+ tabBarItem?.contentView?.badgeColor = kFE352BColor
|
|
|
+ tabBarItem?.contentView?.badgeValue = ""
|
|
|
+ tabBarItem?.contentView?.badgeOffset = UIOffset(horizontal: 0, vertical: -22)
|
|
|
+ }else {
|
|
|
+ let tabBarItem = v5.tabBarItem as? ESTabBarItem
|
|
|
+ tabBarItem?.contentView?.badgeValue = nil
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ func reloadTabbar(index:Int) {
|
|
|
+
|
|
|
+ if index == 0 && lastIndex == 0 {
|
|
|
+ self.lottieAnimateContentView1.animationView.stop()
|
|
|
+ self.lottieAnimateContentView1.animationView.play()
|
|
|
|
|
|
+ if communityModuleTopType == .communityModuleFollowTop {
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name("CommunityModuleFollowTop"), object: nil)
|
|
|
+
|
|
|
+ }
|
|
|
+ if communityModuleTopType == .communityModuleRecommendTop {
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name("CommunityModuleRecommendTop"), object: nil)
|
|
|
+
|
|
|
+ }
|
|
|
+ if communityModuleTopType == .communityModulePlanetTop {
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name("CommunityModulePlanetTop"), object: nil)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if index == 1 && lastIndex == 1 {
|
|
|
+ self.lottieAnimateContentView2.animationView.stop()
|
|
|
+ self.lottieAnimateContentView2.animationView.play()
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name("ShoppingMallModuleTop"), object: nil)
|
|
|
+ // NotificationCenter.default.post(name: NSNotification.Name("RedemptionAreaModuleTop"), object: nil)
|
|
|
+
|
|
|
+ }
|
|
|
+ if index == 3 && lastIndex == 3 {
|
|
|
+ self.lottieAnimateContentView4.animationView.stop()
|
|
|
+ self.lottieAnimateContentView4.animationView.play()
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name("MessageModuleTop"), object: nil)
|
|
|
+
|
|
|
+ }
|
|
|
+ if index == 4 && lastIndex == 4 {
|
|
|
+ self.lottieAnimateContentView5.animationView.stop()
|
|
|
+ self.lottieAnimateContentView5.animationView.play()
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name("MineModuleTop"), object: nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|