| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- //
- // BaseViewController.swift
- // MTP2_iOS
- //
- // Created by Muchinfo on 2020/12/28.
- // Copyright © 2020 Muchinfo. All rights reserved.
- //
- import UIKit
- import JXSegmentedView
- import IBAnimatable
- import NVActivityIndicatorView
- /// 视图容器控制类基类
- class BaseViewController: UIViewController {
-
- // MARK: - 属性列表
- /// 无数据按钮
- @IBOutlet weak var noDataButton: UIButton! {
- didSet {
- noDataButton.set(image: UIImage.getImage(name: "noData-universal"), title: "没有查询记录", titlePosition: .bottom, additionalSpacing: 20.0, state: .normal)
- noDataButton.tintColor = .hex999()
- noDataButton.setTitleColor(.fromHex(rgbValue: 0x68AADD), for: .normal)
- noDataButton.isHidden = true
- }
- }
- /// indicator
- let indicator: JXSegmentedIndicatorImageView = {
- $0.indicatorWidth = 110.0
- $0.indicatorHeight = 3.0
- $0.image = UIImage(named: "segment_line")
- return $0
- } (JXSegmentedIndicatorImageView())
-
- /// segmentedDataSource
- let dataSource: JXSegmentedTitleDataSource = {
- $0.titleNormalColor = .hex333()
- $0.titleNormalFont = .font_13
- $0.titleSelectedColor = .hex368FDF()
- $0.titleSelectedFont = .font_16
- $0.isTitleColorGradientEnabled = true
- return $0
- } (JXSegmentedTitleDataSource())
-
- /// backgroundIndicator
- let backgroundIndicator: JXSegmentedIndicatorBackgroundView = {
- $0.indicatorColor = .hex368FDF()
- return $0
- } (JXSegmentedIndicatorBackgroundView())
-
- /// segmentedDataSource
- let subDataSource: JXSegmentedTitleDataSource = {
- $0.titleNormalColor = .hex333()
- $0.titleNormalFont = .font_13
- $0.titleSelectedColor = .white
- $0.titleSelectedFont = .font_13
- $0.isTitleColorGradientEnabled = true
- return $0
- } (JXSegmentedTitleDataSource())
-
- /// 携带数据信息
- var takeInfo: Any?
- /// 动画对象
- var _anim: NVActivityIndicatorView?
- /// 返回回调
- var popBlock: ((_ takeInfo: Any?) -> Void)?
- /// 周期配置
- var options = SegmentioOptions(backgroundColor: .f6f6f8(),
- segmentPosition: .fixed(maxVisibleItems: 7),
- scrollEnabled: true,
- indicatorOptions: SegmentioIndicatorOptions(type: .bottom, ratio: 1.0, height: 2.0, color: .orange),
- horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions(type: .bottom, height: 0.5, color: UIColor.lightGray.withAlphaComponent(0.6)),
- verticalSeparatorOptions: SegmentioVerticalSeparatorOptions(ratio: 0.1, color: .clear),
- imageContentMode: .center,
- labelTextAlignment: .center,
- labelTextNumberOfLines: 1,
- segmentStates: SegmentioStates(
- defaultState: SegmentioState(
- backgroundColor: .clear,
- titleFont: .font_12,
- titleTextColor: .hex333()
- ),
- selectedState: SegmentioState(
- backgroundColor: .clear,
- titleFont: .font_13,
- titleTextColor: .orange
- ),
- highlightedState: SegmentioState(
- backgroundColor: UIColor.lightGray.withAlphaComponent(0.6),
- titleFont: .font_12,
- titleTextColor: .orange
- )
- ), animationDuration: 0.2)
-
- /// 提示信息视图
- lazy var info: UILabel = {
- $0.numberOfLines = 0
- $0.textColor = .hex333()
- $0.textAlignment = .center
- $0.font = .font_12
- return $0
- } (UILabel(frame: CGRect(origin: CGPoint.zero, size: CGSize(width: self.view.width*0.9, height: 180.0))))
-
- // MARK: - 生命周期
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- /// UI界面初始化
- buildView()
- }
-
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
-
- /// 不允许横屏
- let app = UIApplication.shared.delegate as? AppDelegate
- app?.isRotation = false
- }
-
- override func viewWillDisappear(_ animated: Bool) {
- super.viewDidDisappear(animated)
-
- /// 允许横屏
- let app = UIApplication.shared.delegate as? AppDelegate
- app?.isRotation = true
- }
-
- // MARK: - 初始化
- /// UI界面初始化
- func buildView() {
- // Do any additional setup after loading the view.
- addBackBarButtonItem(false)
- }
-
- /// 添加返回按钮
- /// - Parameter isHidden: 是否显示
- func addBackBarButtonItem(_ isHidden: Bool = false, _ image: String = "back") {
- if !isHidden {
- self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: image)?.withRenderingMode(.alwaysOriginal), style: .done, target: self, action: #selector(onBackBarButtonItemPressed))
- // self.navigationItem.leftBarButtonItem?.tintColor = .white
- } else {
- self.navigationItem.leftBarButtonItem = nil
- }
- }
- /// 加载页面
- func addLoadingView() {
- /// Loading
- _anim = NVActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 50, height: 50), type: .ballSpinFadeLoader, color: UIColor.loding(), padding: 0)
- _anim!.center = self.view.center
- self.view.addSubview(_anim!)
- }
-
- // MARK: - 页面跳转
- /// push
- /// - Parameters:
- /// - sbname: storyboardName
- /// - sbId: storyboardId
- /// - takeInfo: takeInfo
- func push(_ sbname:String, _ sbId:String, _ takeInfo: Any? = nil) {
- let board: UIStoryboard = UIStoryboard.init(name: sbname, bundle: nil)
- if let baseViewController = board.instantiateViewController(withIdentifier: sbId) as? BaseViewController,
- let model = takeInfo {
- baseViewController.takeInfo = model
- self.navigationController?.pushViewController(baseViewController, animated: true)
- } else {
- let viewController = board.instantiateViewController(withIdentifier: sbId)
- self.navigationController?.pushViewController(viewController, animated: true)
- }
- }
-
- /// present
- /// - Parameters:
- /// - sbname: sbname
- /// - sbId: sbId
- /// - isNav: isNav
- /// - style: modalTransitionStyle
- func present(_ sbname: String, _ sbId:String, _ isNav: Bool = true, _ style: UIModalTransitionStyle = .crossDissolve, _ takeInfo: Any? = nil) {
- let board: UIStoryboard = UIStoryboard.init(name: sbname, bundle: nil)
- if let viewController = board.instantiateViewController(withIdentifier: sbId) as? BaseViewController {
- viewController.takeInfo = takeInfo
- if isNav {
- let navigationController = BaseNavigationController(rootViewController: viewController)
- navigationController.modalPresentationStyle = .overFullScreen
- navigationController.modalTransitionStyle = style
- self.present(navigationController, animated: true, completion: nil)
- } else {
- viewController.modalPresentationStyle = .overFullScreen
- viewController.modalTransitionStyle = style
- self.present(viewController, animated: true, completion: nil)
- }
- } else if let viewController = board.instantiateViewController(withIdentifier: sbId) as? BaseNavigationController {
- viewController.modalPresentationStyle = .overFullScreen
- viewController.modalTransitionStyle = style
- self.present(viewController, animated: true, completion: nil)
- }
- }
-
- /// 返回按钮点击事件
- @objc func onBackBarButtonItemPressed() {
- if (self.navigationController?.viewControllers.count ?? 0) > 1 {
- self.navigationController?.popViewController(animated: true)
- } else {
- self.dismiss(animated: true, completion: {})
- }
- }
- }
|