123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- //
- // BaseViewController.swift
- // JSJP_Student_sw
- //
- // Created by Ning.ge on 2023/5/30.
- //
- import UIKit
- import RxSwift
- import RxCocoa
- import ReactorKit
- import RxDataSources
- class BaseViewController: UIViewController, NetAnimationLoadable {
- public struct Metric {
- static let statusBarHeight = isIphoneX ? 44.f : 20.f
- static let navBarHeight = 44.f
- }
-
- @IBOutlet weak var nav_top_layout: NSLayoutConstraint!
- @IBOutlet weak var nav_topH_layout: NSLayoutConstraint!
- // MARK: Properties
- lazy private(set) var className: String = {
- return type(of: self).description().components(separatedBy: ".").last ?? ""
- }()
-
- @IBAction func actionBackdo(_ sender: Any) {
- if let presentingViewController = self.presentingViewController {
- // 视图控制器是通过 presentViewController 呈现的
- if self.navigationController?.viewControllers.count == 1 {
- self.dismiss(animated: true)
- return
- }
- }
- self.navigationController?.popViewController(animated: true)
- }
- /// There is a bug when trying to go back to previous view controller in a navigation controller
- /// on iOS 11, a scroll view in the previous screen scrolls weirdly. In order to get this fixed,
- /// we have to set the scrollView's `contentInsetAdjustmentBehavior` property to `.never` on
- /// `viewWillAppear()` and set back to the original value on `viewDidAppear()`.
- private var scrollViewOriginalContentInsetAdjustmentBehaviorRawValue: Int?
-
- // MARK: Initializing
- init() {
- super.init(nibName: nil, bundle: nil)
- }
-
- init(nibName:String) {
- super.init(nibName: nibName, bundle: nil)
- }
- required convenience init?(coder aDecoder: NSCoder) {
- self.init()
- }
-
- deinit {
- NotificationCenter.default.removeObserver(self)
- log.verbose("DEINIT: \(self.className)")
- }
-
- // MARK: Rx
- var disposeBag = DisposeBag()
-
- // MARK: View Lifecycle
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- navigationController?.navigationBar.isHidden = true
- // fix iOS 11 scroll view bug
- if #available(iOS 11, *) {
- if let scrollView = self.view.subviews.first as? UIScrollView {
- self.scrollViewOriginalContentInsetAdjustmentBehaviorRawValue =
- scrollView.contentInsetAdjustmentBehavior.rawValue
- scrollView.contentInsetAdjustmentBehavior = .never
- }
- }
- }
-
- // //状态栏颜色
- // override var preferredStatusBarStyle: UIStatusBarStyle{
- // return .lightContent
- // }
-
- override func viewDidAppear(_ animated: Bool) {
- super.viewDidAppear(animated)
-
- // fix iOS 11 scroll view bug
- if #available(iOS 11, *) {
- if let scrollView = self.view.subviews.first as? UIScrollView,
- let rawValue = self.scrollViewOriginalContentInsetAdjustmentBehaviorRawValue,
- let behavior = UIScrollView.ContentInsetAdjustmentBehavior(rawValue: rawValue) {
- scrollView.contentInsetAdjustmentBehavior = behavior
- }
- }
- }
-
- // MARK: Layout Constraints
-
- private(set) var didSetupConstraints = false
-
- override func viewDidLoad() {
-
- self.view.setNeedsUpdateConstraints()
-
- self.edgesForExtendedLayout = []
- }
-
- override func updateViewConstraints() {
- if !self.didSetupConstraints {
- self.setupConstraints()
- self.didSetupConstraints = true
- }
- super.updateViewConstraints()
- }
-
- func setupConstraints() {
- // Override point
- }
-
- }
|