fix
杨锴
2025-05-06 fdb1d18a0b4b941b986d55f66c589e29836494eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
//  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!))
                }
 
}