// // 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! // 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 { 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 } }