MainViewController.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // MainViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by zhongyuan on 2018/5/19.
  6. // Copyright © 2018年 zhongyuan.All rights reserved.
  7. //
  8. import UIKit
  9. import NVActivityIndicatorView
  10. import WHToast
  11. /// 主窗体
  12. class MainViewController: UITabBarController {
  13. // MARK: - 生命周期相关
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. /// 设置委托代理
  17. self.delegate = self
  18. /// 初始化界面
  19. buildView()
  20. }
  21. // MARK: - 加载配置项功能相关
  22. private func buildView() {
  23. /// 设置tabbar背景色
  24. self.tabBar.barTintColor = UIColor.white
  25. /// 去掉毛玻璃效果
  26. self.tabBar.isTranslucent = false
  27. if let fundations = ConfigUtils.getValue(key: .functionModule) as? [String] {
  28. var viewcontrollers = [UIViewController]()
  29. for id in fundations {
  30. if id == "Home" { /// 首页
  31. let navigationController = UIStoryboard(name: "Home", bundle: nil).instantiateViewController(withIdentifier: "Home") as! BaseNavigationController
  32. viewcontrollers.append(navigationController)
  33. } else if id == "Mine" { /// 我的页面
  34. let navigationController = UIStoryboard(name: "Mine", bundle: nil).instantiateViewController(withIdentifier: "Mine") as! BaseNavigationController
  35. viewcontrollers.append(navigationController)
  36. } else if id == "Quote" { /// 行情
  37. let navigationController = UIStoryboard(name: "Quote", bundle: nil).instantiateViewController(withIdentifier: "Quote") as! BaseNavigationController
  38. viewcontrollers.append(navigationController)
  39. } else if id == "Message" { /// 消息
  40. let navigationController = UIStoryboard(name: "Message", bundle: nil).instantiateViewController(withIdentifier: "Message") as! BaseNavigationController
  41. viewcontrollers.append(navigationController)
  42. }
  43. }
  44. self.viewControllers = viewcontrollers
  45. }
  46. }
  47. }
  48. extension MainViewController: UITabBarControllerDelegate {
  49. func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
  50. /// 未登录
  51. if let sub = (viewController as? BaseNavigationController)?.viewControllers[0],
  52. sub.isKind(of: MessageViewController.self),
  53. !MTP2BusinessCore.shared.getLoginStatus() {
  54. /// 弹出登录页面
  55. tabBarController.viewControllers?[0].present(storyboardName: "Main", storyboardId: "Login")
  56. return false
  57. }
  58. return true
  59. }
  60. }