//
|
// BaseViewController.swift
|
// BrokerDriver
|
//
|
// Created by 无故事王国 on 2023/4/24.
|
//
|
|
import UIKit
|
import RxSwift
|
import RxRelay
|
import RxCocoa
|
import JQTools
|
import QMUIKit
|
|
class BaseVC: UIViewController {
|
|
var disposeBag:DisposeBag!
|
let refreshStatus = BehaviorSubject(value: RefreshStatus.others)
|
|
var yy_popBlock:(() -> Void)?
|
open var nav_back_img:UIImage = UIImage.init(named: "btn_back") ?? UIImage.init() {
|
didSet {
|
let btn = navigationItem.leftBarButtonItem?.customView as! UIButton
|
btn.setImage(nav_back_img, for: .normal)
|
}
|
}
|
|
override func viewWillAppear(_ animated: Bool) {
|
super.viewWillAppear(animated)
|
navigationController?.delegate?.navigationController?(navigationController!, willShow: self, animated: true)
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
|
disposeBag = DisposeBag()
|
setUI()
|
setRx()
|
setData()
|
|
if navigationController?.viewControllers.count ?? 0 > 1{
|
let backButton = QMUIButton(type: .custom)
|
backButton.setImage(UIImage(named: "btn_back"), for: .normal)
|
backButton.setTitle(self.title, for: .normal)
|
backButton.setTitleColor(.black.withAlphaComponent(0.81), for: .normal)
|
backButton.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: .medium)
|
backButton.imagePosition = .left
|
backButton.spacingBetweenImageAndTitle = 35
|
backButton.addTarget(self, action: #selector(backItemEvent), for: .touchUpInside)
|
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backButton)
|
}
|
|
if !self.isKind(of: HomeVC.self) && !self.isKind(of: HomeListenSubVC.self) && !self.isKind(of: HomeListenFight_lesson_1_VC.self) && !self.isKind(of: HomeListenFight_lesson_2_VC.self) && !self.isKind(of: HomeListenFight_lesson_3_VC.self) && !self.isKind(of: HomeListenFight_lesson_4_VC.self) && !self.isKind(of: HomeListenFight_lesson_5_VC.self) && !self.isKind(of: HomeListenGame_1_VC.self) && !self.isKind(of: HomeListenGame_2_VC.self) && !self.isKind(of: HomeListenStory_1_VC.self) && !self.isKind(of: HomeListenStory_2_VC.self) && !self.isKind(of: LoginVC.self){
|
let titleV = UIView()
|
// titleV.bounds = CGRect(x: 0, y: 0, width: 156, height: 24)
|
titleV.sizeToFit()
|
let imgV = UIImageView(image: UIImage(named: "bg_logo"))
|
imgV.contentMode = .scaleAspectFit
|
titleV.addSubview(imgV)
|
imgV.snp.makeConstraints { make in
|
make.edges.equalToSuperview()
|
}
|
|
view.addSubview(titleV)
|
titleV.snp.makeConstraints { make in
|
make.center.equalToSuperview()
|
}
|
|
navigationItem.titleView = titleV
|
}
|
}
|
|
func setRx(){
|
}
|
|
func setUI(){
|
view.backgroundColor = Config.ThemeBGColor
|
|
}
|
|
func setData(){
|
|
}
|
|
func refreshUI(){}
|
|
func push(vc:UIViewController){
|
vc.hidesBottomBarWhenPushed = true
|
navigationController?.pushViewController(vc, animated: true)
|
}
|
|
override var preferredStatusBarStyle: UIStatusBarStyle{
|
return .lightContent
|
}
|
|
@objc fileprivate func backItemEvent() {
|
// 拦截pop事件
|
if (yy_popBlock != nil) {
|
yy_popBlock?()
|
return
|
}
|
navigationController?.popViewController(animated: true)
|
}
|
|
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
coordinator.animate(alongsideTransition: { [weak self] (context) in
|
let orient = UIApplication.shared.statusBarOrientation
|
switch orient {
|
case .landscapeLeft, .landscapeRight:
|
//横屏时禁止左拽滑出
|
self?.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
|
default:
|
//竖屏时允许左拽滑出
|
self?.navigationController?.interactivePopGestureRecognizer?.isEnabled = true
|
}
|
})
|
super.viewWillTransition(to: size, with: coordinator)
|
}
|
|
|
deinit {
|
LogInfo(String(format: "%@ 已释放", NSStringFromClass(self.classForCoder).components(separatedBy: ".").last!))
|
}
|
|
}
|