| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- //
- // QuoteViewController.swift
- // MTP2_iOS
- //
- // Created by Handy_Cao on 2020/10/23.
- // Copyright © 2020 Muchinfo. All rights reserved.
- //
- import UIKit
- import SwiftyAttributes
- import JXSegmentedView
- import WHToast
- /// 商品行情视图容器控制类
- class QuoteViewController: BaseViewController {
-
- // MARK: - 属性列表
- /// 分段控制器
- @IBOutlet weak var segmentedView: JXSegmentedView! {
- didSet {
- segmentedView.delegate = self
- segmentedView.dataSource = dataSource
- segmentedView.indicators = [self.indicator]
- }
- }
- /// 内容装载视图
- @IBOutlet weak var contentStackView: UIStackView!
- /// 海南网警
- @IBOutlet weak var police: UIButton!
- /// 检索按钮
- @IBOutlet weak var search: UIButton!
- /// 类目按钮
- @IBOutlet weak var category: UIButton!
-
- /// segmentedDataSource
- let dataSource: JXSegmentedTitleDataSource = {
- $0.titleNormalColor = UIColorFromHex(rgbValue: 0x333333)
- $0.titleNormalFont = .font_16
- $0.titleSelectedColor = UIColorFromHex(rgbValue: 0x60a1e3)
- $0.titleSelectedFont = .font_18
- $0.isTitleColorGradientEnabled = true
- return $0
- } (JXSegmentedTitleDataSource())
-
- /// 热卖商品视图
- lazy var hotQuoteController: HotQuoteViewController = {
- $0.view.frame = contentStackView.bounds
- return $0
- } (UIStoryboard(name: "Quote", bundle: nil).instantiateViewController(withIdentifier: "HotQuote") as! HotQuoteViewController)
-
- // /// 新品上市视图
- // lazy var newQuoteController: NewQuoteViewController = {
- // $0.view.frame = contentStackView.bounds
- // return $0
- // } (UIStoryboard(name: "Quote", bundle: nil).instantiateViewController(withIdentifier: "NewQuote") as! NewQuoteViewController)
-
- /// 特卖商城
- lazy var specialSaleController: SpecialSaleViewController = {
- $0.view.frame = contentStackView.bounds
- return $0
- } (UIStoryboard(name: "Quote", bundle: nil).instantiateViewController(withIdentifier: "SpecialSale") as! SpecialSaleViewController)
- // MARK: - 生命周期相关
- required init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
-
- /// 设置TabBar图片
- self.tabBarItem.image = UIImage(named: "quote_normal")?.withRenderingMode(.alwaysOriginal)
- self.tabBarItem.selectedImage = UIImage(named: "quote_selected")?.withRenderingMode(.alwaysOriginal)
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- /// 不需要返回按钮
- addBackBarButtonItem(true)
- /// UI界面显示
- buildView()
- }
-
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- /// 刷新数据
- dataSource.titles = ["热卖商品", "竞价商品"]
- segmentedView.reloadData()
- /// 隐藏导航栏
- self.navigationController?.setNavigationBarHidden(true, animated: true)
- }
-
- // MARK: - 初始化
- /// UI界面显示
- fileprivate func buildView() {
- showController(selectedIndex: 0)
- }
-
- // MARK: - 交互相关
- @IBAction func onButtonPressed(_ sender: UIButton) {
- switch sender {
- case police: /// 海南网警
- push(storyboardName: "Feedback", storyboardId: "Feedback")
- case category: /// 类目
- let category = viewController(name: "Category", identifier: "CategoryID")
- self.navigationController?.pushViewController(category, animated: true)
- default: break
- }
- }
-
- // MARK: - UI显示
- /// Tab也切换时显示的容器
- /// - Parameter index: index
- fileprivate func showController(selectedIndex index: Int) {
- switch index {
- case 0: /// 热卖商品
- /// 移出新品上市视图
- removeChildren(hotQuoteController)
- // /// 移出新品上市视图
- // removeChildren(newQuoteController)
- /// 添加特卖商城视图
- addChildren(specialSaleController)
- // case 1:
- // /// 移出新品上市视图
- // removeChildren(hotQuoteController)
- // /// 移出新品上市视图
- // removeChildren(specialSaleController)
- // /// 添加特卖商城视图
- // addChildren(newQuoteController)
- default: /// 竞价商品
- // /// 移出新品上市视图
- // removeChildren(newQuoteController)
- /// 移出新品上市视图
- removeChildren(specialSaleController)
- /// 添加特卖商城视图
- addChildren(hotQuoteController)
- }
- }
-
- /// addChildren
- /// - Parameter child: child
- fileprivate func addChildren(_ child: UIViewController) {
- if !contentStackView.arrangedSubviews.contains(child.view) {
- self.addChild(child)
- child.didMove(toParent: self)
- contentStackView.addArrangedSubview(child.view)
- }
- }
-
- /// removeChildren
- /// - Parameter child: child
- fileprivate func removeChildren(_ child: UIViewController) {
- if contentStackView.arrangedSubviews.contains(child.view) {
- child.removeFromParent()
- contentStackView.removeArrangedSubview(child.view)
- child.view.removeFromSuperview()
- }
- }
-
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- }
- }
- extension QuoteViewController: JXSegmentedViewDelegate {
-
- func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
- /// 显示相应的视图
- self.showController(selectedIndex: index)
- /// 隐藏分类按钮
- self.category.isHidden = !(index == 0)
- }
- }
|