//
|
// YYStaticTableViewController.swift
|
// XinYuDriver
|
//
|
// Created by alvin_y on 2020/3/23.
|
// Copyright © 2020 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
import RxCocoa
|
import RxSwift
|
import MBProgressHUD
|
//import SwifterSwift
|
class YYStaticTableViewController: UITableViewController,UIGestureRecognizerDelegate {
|
|
// 调用此属性会自动拦截pop
|
open var yy_popBlock:(() -> Void)?
|
|
/// 导航栏黑线
|
var nav_bar_hair_line_imageView : UIImageView?
|
|
let disposeBag = DisposeBag()
|
|
/// MBProgressHUD
|
var hud : MBProgressHUD?
|
|
// 导航栏返回按钮图片
|
open var yy_nav_back_img:UIImage = UIImage.init(named: "back") ?? UIImage.init() {
|
didSet {
|
if yy_isHiddenBackItem {
|
let btn = navigationItem.leftBarButtonItem?.customView as! UIButton
|
btn.setImage(yy_nav_back_img, for: .normal)
|
|
} else {
|
yy_isHiddenBackItem = true
|
}
|
}
|
}
|
|
// 是否需要返回按钮
|
open var yy_isHiddenBackItem:Bool = false {
|
didSet {
|
if yy_isHiddenBackItem {
|
navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "", style: .done, target: nil, action: nil)
|
} else {
|
navigationItem.leftBarButtonItem = UIBarButtonItem.yy_creat(image: yy_nav_back_img, target: self, alignment:.left, action: #selector(backItemEvent)).item
|
}
|
}
|
}
|
|
// 是否需要返回手势
|
open var yy_isEnabledBackTap:Bool = true {
|
didSet {
|
if yy_isEnabledBackTap {
|
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true
|
} else {
|
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
|
}
|
}
|
}
|
|
/// 是否需要导航栏黑线
|
open var yy_isHiddenNavBarLine:Bool = false {
|
didSet {
|
if yy_isHiddenNavBarLine {
|
nav_bar_hair_line_imageView?.isHidden = true
|
} else {
|
nav_bar_hair_line_imageView?.isHidden = false
|
}
|
}
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
// Do any additional setup after loading the view.
|
// 隐藏之后navigationBar不存在导致cash
|
if let nav = navigationController?.navigationBar{
|
nav_bar_hair_line_imageView = findHairlineImageViewUnder(view: nav)
|
}
|
view.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
|
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:#colorLiteral(red: 0, green: 0, blue: 0, alpha: 1),NSAttributedString.Key.font: UIFont.init(name: Semibold, size: 18) ?? UIFont.systemFont(ofSize: 18)]
|
self.navigationController?.navigationBar.barTintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
|
self.navigationController?.navigationBar.shadowImage = UIImage.init(color: #colorLiteral(red: 0.9529411765, green: 0.9529411765, blue: 0.9529411765, alpha: 1))
|
yy_isHiddenBackItem = false
|
yy_isHiddenNavBarLine = false
|
setupViews()
|
defineLayouts()
|
bindRx()
|
request()
|
}
|
|
override func viewWillAppear(_ animated: Bool) {
|
super.viewWillAppear(animated)
|
self.navigationController?.interactivePopGestureRecognizer?.delegate = self
|
}
|
|
//MARK: - 初始化或者配置所有的view,此方法将在UIViewController的viewDidLoad()方法中调用
|
func setupViews() {
|
|
}
|
|
//MARK: - 定义布局,在这里添加约束,此方法将在UIViewController的viewDidLoad()方法中调用
|
func defineLayouts() {
|
|
}
|
|
//MARK: - 绑定ViewModel中的数据,此方法将在UIViewController的viewDidLoad()方法中调用
|
func bindRx() {
|
|
}
|
|
//MARK: - 请求数据,此方法将在UIViewController的viewDidLoad()方法中调用
|
func request() {
|
|
}
|
|
//MARK: - NavigationController
|
// pop点击事件
|
@objc fileprivate func backItemEvent() {
|
|
// 拦截pop事件
|
if (yy_popBlock != nil) {
|
yy_popBlock?()
|
return
|
}
|
|
yy_pop()
|
}
|
|
/// UIStatusBarStyle
|
override var preferredStatusBarStyle: UIStatusBarStyle{
|
return .default
|
}
|
|
/// 找到导航栏的线条并选择显示或隐藏
|
/// - Parameter view: 导航栏View
|
func findHairlineImageViewUnder(view: UIView) -> UIImageView?{
|
if view.isKind(of: UIImageView.classForCoder()) && view.bounds.size.height <= 1.0{
|
return view as? UIImageView
|
}
|
for subView in view.subviews {
|
let imageView = self.findHairlineImageViewUnder(view: subView)
|
if (imageView != nil){
|
return imageView
|
}
|
}
|
return nil
|
}
|
|
|
/// pop
|
/// - Parameter animated: animated
|
open func yy_pop(_ animated:Bool = true) {
|
navigationController?.popViewController(animated: animated)
|
}
|
|
/// yy_popToRoot
|
/// - Parameter animated: animated
|
open func yy_popToRoot(_ animated: Bool = true) {
|
navigationController?.popToRootViewController(animated: animated)
|
}
|
|
/// yy_push
|
/// - Parameters:
|
/// - vc: UIViewController
|
/// - animated: animated
|
/// - hiddenBottom: hiddenBottom
|
open func yy_push(vc:UIViewController, _ animated:Bool = true, _ hiddenBottom:Bool = true) {
|
vc.hidesBottomBarWhenPushed = hiddenBottom
|
self.navigationController?.pushViewController(vc, animated: animated)
|
}
|
|
/// push
|
///
|
/// - Parameters:
|
/// - vc: UIViewController
|
/// - animated: animated
|
/// - hiddenBottom: hiddenBottom
|
open func wy_pushAnimate(vc:UIViewController, _ animated:Bool = false, _ hiddenBottom:Bool = true){
|
let transition = CATransition()
|
transition.duration = 0.3
|
transition.type = .moveIn
|
transition.subtype = .fromTop
|
navigationController?.view.layer.add(transition, forKey: kCATransition)
|
vc.hidesBottomBarWhenPushed = hiddenBottom
|
navigationController?.pushViewController(vc, animated: animated)
|
}
|
|
|
/// yy_present
|
/// - Parameter vc: UIViewController
|
open func yy_present(vc:UIViewController){
|
vc.modalPresentationStyle = .custom
|
vc.transitioningDelegate = self
|
vc.view.frame = CGRect(x: 0, y: 0, width: screenW, height: screenH)
|
self.present(vc, animated: true, completion: nil)
|
}
|
|
//MARK: - MBProgressHUD
|
/// 不带文字
|
func show() {
|
hud = build()
|
}
|
|
func hide() {
|
hud?.hide(animated: true)
|
}
|
|
func build() -> MBProgressHUD {
|
let hud = MBProgressHUD.showAdded(to: UIApplication.shared.keyWindow!, animated: true)
|
hud.mode = .indeterminate
|
return hud
|
}
|
|
|
// MARK: - Table view data source
|
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
// #warning Incomplete implementation, return the number of sections
|
return super.numberOfSections(in: tableView)
|
}
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
// #warning Incomplete implementation, return the number of rows
|
return super.tableView(tableView, numberOfRowsInSection: section)
|
}
|
}
|
// MARK: - UIViewControllerTransitioningDelegate
|
extension YYStaticTableViewController: UIViewControllerTransitioningDelegate{
|
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
return DismissAnimation()
|
}
|
|
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
return PresentAnimation()
|
}
|
}
|