|
@@ -0,0 +1,264 @@
|
|
|
+//
|
|
|
+// BaseTabbarViewController.swift
|
|
|
+// RainbowPlanet
|
|
|
+//
|
|
|
+// Created by 南鑫林 on 2019/3/8.
|
|
|
+// Copyright © 2019 南鑫林. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+import UIKit
|
|
|
+import Lottie
|
|
|
+import ESTabBarController_swift
|
|
|
+
|
|
|
+class BaseTabbarViewController: NSObject {
|
|
|
+
|
|
|
+ static let shared : BaseTabbarViewController = BaseTabbarViewController()
|
|
|
+
|
|
|
+ var esTabBarController : ESTabBarController!
|
|
|
+
|
|
|
+ /// 社区
|
|
|
+ var v1 : CommunityViewController!
|
|
|
+ /// 商城
|
|
|
+// var v2 = ShoppingMallViewController!
|
|
|
+ /// 兑换专区
|
|
|
+ var v2 : RedemptionAreaViewController!
|
|
|
+ /// 发布
|
|
|
+ var v3 : BaseViewController!
|
|
|
+ /// 消息
|
|
|
+ var v4 : MessageMainViewController!
|
|
|
+ /// 我的
|
|
|
+ var v5 : UserPersonalCenterViewController!
|
|
|
+
|
|
|
+ /// 社区
|
|
|
+ var lottieAnimateContentView1 : BaseLottieAnimateContentView!
|
|
|
+
|
|
|
+ /// 商城
|
|
|
+ var lottieAnimateContentView2 : BaseLottieAnimateContentView!
|
|
|
+
|
|
|
+ /// 消息
|
|
|
+ var lottieAnimateContentView4 : BaseLottieAnimateContentView!
|
|
|
+
|
|
|
+ /// 我的
|
|
|
+ var lottieAnimateContentView5 : BaseLottieAnimateContentView!
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var lastIndex : Int = 0
|
|
|
+
|
|
|
+ func tabBarViewController() -> ESTabBarController {
|
|
|
+ esTabBarController = ESTabBarController()
|
|
|
+
|
|
|
+ esTabBarController.tabBar.shadowImage = UIImage(named: "navbar_shadow_pic_down")
|
|
|
+ esTabBarController.shouldHijackHandler = {
|
|
|
+ [weak self] (tabbarController, viewController, index) in
|
|
|
+ AudioServicesPlaySystemSound(1519)
|
|
|
+
|
|
|
+ if UserModel.isTokenNil() {
|
|
|
+ if index == 2 || index == 3 || index == 4 {
|
|
|
+ return true
|
|
|
+ }else {
|
|
|
+ self?.reloadTabbar(index:index)
|
|
|
+ self?.lastIndex = index
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if index == 2 {
|
|
|
+ self?.lastIndex = index
|
|
|
+ return true
|
|
|
+ }else {
|
|
|
+ self?.reloadTabbar(index:index)
|
|
|
+ self?.lastIndex = index
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ esTabBarController.didHijackHandler = {
|
|
|
+ [weak self] tabbarController, viewController, index in
|
|
|
+ if UserModel.isTokenNil() {
|
|
|
+ kAppDelegate.setLogin()
|
|
|
+ }else {
|
|
|
+ self?.pushPublishVC()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 社区
|
|
|
+ v1 = CommunityViewController()
|
|
|
+ /// 商城
|
|
|
+ // var v2 = ShoppingMallViewController!
|
|
|
+ /// 兑换专区
|
|
|
+ v2 = RedemptionAreaViewController()
|
|
|
+ /// 发布
|
|
|
+ v3 = BaseViewController()
|
|
|
+ /// 消息
|
|
|
+ v4 = MessageMainViewController()
|
|
|
+ /// 我的
|
|
|
+ v5 = UserPersonalCenterViewController()
|
|
|
+
|
|
|
+ /// 社区
|
|
|
+ lottieAnimateContentView1 = BaseLottieAnimateContentView(jsonStr: "communityModuleTabbar")
|
|
|
+
|
|
|
+ /// 商城
|
|
|
+ lottieAnimateContentView2 = BaseLottieAnimateContentView(jsonStr: "shoppingMallModuleTabbar")
|
|
|
+
|
|
|
+ /// 消息
|
|
|
+ lottieAnimateContentView4 = BaseLottieAnimateContentView(jsonStr: "messageModuleTabbar")
|
|
|
+
|
|
|
+ /// 我的
|
|
|
+ lottieAnimateContentView5 = BaseLottieAnimateContentView(jsonStr: "MineModuleTabbar")
|
|
|
+
|
|
|
+ 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")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal), 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);
|
|
|
+
|
|
|
+ if UserModel.isTokenNil() {
|
|
|
+ setLoginOutTabBarItem()
|
|
|
+ }else {
|
|
|
+ setLoginTabBarItem()
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)
|
|
|
+
|
|
|
+ esTabBarController.viewControllers = [n1, n2, n3, n4, n5]
|
|
|
+ //将要进入前台的时候
|
|
|
+ setBadge()
|
|
|
+ NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: OperationQueue.main, using: {
|
|
|
+ [weak self] (notification) in
|
|
|
+ if !UserModel.isTokenNil() {
|
|
|
+ //获取消息的小红点
|
|
|
+ MessageModuleManager.shared.userMemberMessageIndexApi()
|
|
|
+ self?.setBadge()
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ //监听消息
|
|
|
+ NotificationCenter.default.addObserver(forName: NSNotification.Name("MessageMainViewController"), object: nil, queue: OperationQueue.main) {
|
|
|
+ [weak self] notification in
|
|
|
+ self?.setBadge()
|
|
|
+ }
|
|
|
+ return esTabBarController
|
|
|
+ }
|
|
|
+
|
|
|
+ func setLoginTabBarItem() {
|
|
|
+ v4.tabBarItem = ESTabBarItem.init(lottieAnimateContentView4, title: "消息", image: UIImage(named: "tabbar_massage")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal), selectedImage: nil)
|
|
|
+ v5.tabBarItem = ESTabBarItem.init(lottieAnimateContentView5, title: "我的", image: UIImage(named: "tabbar_my")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal), selectedImage: nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ func setLoginOutTabBarItem() {
|
|
|
+ v4.tabBarItem = ESTabBarItem.init(BaseTabBarItemContentView(), title: "消息", image: UIImage(named: "tabbar_massage")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal), selectedImage:nil)
|
|
|
+ v5.tabBarItem = ESTabBarItem.init(BaseTabBarItemContentView(), title: "我的", image: UIImage(named: "tabbar_my")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal), selectedImage:nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 跳转到VC
|
|
|
+ func pushPublishVC() {
|
|
|
+ if BaseTabbarViewController.shared.v1.navigationBarbgView.isHidden {
|
|
|
+ let pickVc = PublishViewController()
|
|
|
+// let pickVc = PublishNewViewController()
|
|
|
+ let nav = BaseNavigationViewController.init(rootViewController: pickVc)
|
|
|
+ BaseTabbarViewController.shared.esTabBarController.present(nav, animated: true, completion: nil)
|
|
|
+ } else {
|
|
|
+ SwiftProgressHUD.shared().showText("内容上传中,请稍等", textAlignment: .center)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置Badge
|
|
|
+ func setBadge() {
|
|
|
+ //消息
|
|
|
+ let messageIndexModel = MessageIndexModel.shared.object()
|
|
|
+ if messageIndexModel?.activity?.isYes == 1 || messageIndexModel?.follow?.isYes == 1 || messageIndexModel?.notification?.isYes == 1 || messageIndexModel?.praise?.isYes == 1 || messageIndexModel?.comment?.isYes == 1 {
|
|
|
+ let tabBarItem = v4.tabBarItem as? ESTabBarItem
|
|
|
+ tabBarItem?.contentView?.badgeColor = kFE352BColor
|
|
|
+ tabBarItem?.contentView?.badgeValue = ""
|
|
|
+ tabBarItem?.contentView?.badgeOffset = UIOffset(horizontal: 0, vertical: -22)
|
|
|
+ }else {
|
|
|
+ let tabBarItem = v4.tabBarItem as? ESTabBarItem
|
|
|
+ tabBarItem?.contentView?.badgeValue = nil
|
|
|
+ }
|
|
|
+
|
|
|
+ //我的
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+extension ESTabBar {
|
|
|
+ open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
|
|
+
|
|
|
+ let view = super.hitTest(point, with: event)
|
|
|
+ if view == nil {
|
|
|
+ if UserModel.isTokenNil() && LoginNowView.shared.loginNowView != nil {
|
|
|
+ for subView in subviews {
|
|
|
+ if !subView.subviews.isEmpty {
|
|
|
+ for subView in subView.subviews {
|
|
|
+ let myPoint = subView.convert(point, from: self)
|
|
|
+ if subView.bounds.contains(myPoint) {
|
|
|
+ return subView
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let myPoint = subView.convert(point, from: self)
|
|
|
+ if subView.bounds.contains(myPoint) {
|
|
|
+ return subView
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return view
|
|
|
+ }
|
|
|
+}
|