Skip to content

Commit

Permalink
* 完成自定义转场的接口外露
Browse files Browse the repository at this point in the history
  • Loading branch information
Caffe-del committed Sep 24, 2020
1 parent 4362044 commit 154098a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 5 deletions.
25 changes: 23 additions & 2 deletions BottomBar/BaseNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

import UIKit

enum pushOperation {
case normal
case bottomUp
}

class BaseNavigationController: UINavigationController, UINavigationControllerDelegate {

var popInteractiveTransition: UIPercentDrivenInteractiveTransition?
Expand Down Expand Up @@ -39,9 +44,15 @@ class BaseNavigationController: UINavigationController, UINavigationControllerDe
// 非手势交互转场
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if operation == .push {
return PushAnimatedTransitionAsFromBottomToTop.init()
if toVC.currentPushOperation == .bottomUp {
fromVC.isDelayShowBottomBar = false
return PushAnimatedTransitionAsFromBottomToTop.init()
}
} else if (operation == .pop) {
return PopAnimatedTransitioningAsFromTopToBottom.init()
if fromVC.currentPushOperation == .bottomUp {
toVC.isDelayShowBottomBar = true
return PopAnimatedTransitioningAsFromTopToBottom.init()
}
}
return nil
}
Expand Down Expand Up @@ -136,3 +147,13 @@ extension BaseNavigationController: UIGestureRecognizerDelegate {
}
}

extension UINavigationController {

func RTPushViewController(_ viewController: UIViewController, operation: pushOperation, animated: Bool) {

viewController.currentPushOperation = operation
self.pushViewController(viewController, animated: animated)
}
}


11 changes: 10 additions & 1 deletion BottomBar/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ class BaseViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.extendedLayoutIncludesOpaqueBars = true;
self.automaticallyAdjustsScrollViewInsets = true;
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

}


}
1 change: 1 addition & 0 deletions BottomBar/MusicDetailVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MusicDetailVC: BaseViewController {
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let tabBarController = self.tabBarController as? RootTabBarController {
tabBarController.updateBottomStyle(.none)
}
Expand Down
4 changes: 2 additions & 2 deletions BottomBar/MusicViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class MusicViewController: BaseViewController {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let vc = MusicDetailVC()
vc.modalPresentationStyle = .fullScreen
self.navigationController?.pushViewController(vc, animated: true)
// self.navigationController?.present(vc, animated: true, completion: nil)
self.navigationController?.RTPushViewController(vc, operation: .bottomUp, animated: true)
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let tabBarController = self.tabBarController as? RootTabBarController {
tabBarController.updateBottomStyle(.all)
}
Expand Down
13 changes: 13 additions & 0 deletions BottomBar/Runtime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extension UIViewController {
// 嵌套结构体
private struct AssociatedKeys {
static var isDelayShowBottomBarKey = "isDelayShowBottomBarKey"
static var pushOperationKey = "pushOperationKey"
}

// 当前vc是否需要延迟做动画
Expand All @@ -24,4 +25,16 @@ extension UIViewController {
objc_setAssociatedObject(self, &AssociatedKeys.isDelayShowBottomBarKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}

var currentPushOperation: pushOperation {
get {
if let operation = objc_getAssociatedObject(self, &AssociatedKeys.pushOperationKey) as? pushOperation {
return operation
}
return .normal
}
set {
objc_setAssociatedObject(self, &AssociatedKeys.pushOperationKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
1 change: 1 addition & 0 deletions BottomBar/VideoDetailVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class VideoDetailVC: BaseViewController {
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let tabBarController = self.tabBarController as? RootTabBarController {
tabBarController.updateBottomStyle(.miniPlayViewOnly)
}
Expand Down
1 change: 1 addition & 0 deletions BottomBar/VideoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class VideoViewController: BaseViewController {
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let tabBarController = self.tabBarController as? RootTabBarController {
tabBarController.updateBottomStyle(.all)
}
Expand Down

0 comments on commit 154098a

Please sign in to comment.