To run the example project, clone the repo, and run pod install
from the Example directory first.
BDNavigationBarTransition is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'BDNavigationBarTransition'
导航栏不同颜色切换
有导航栏切换到无导航栏
渐变色导航栏切换
导航栏滑动显示
1. Define your custom navigationbar style
//CustomNavigationBarStyle.swift
extension CommonNavigationBarStyle {
static var red: CommonNavigationBarStyle {
let style = CommonNavigationBarStyle()
style.barBackgroundColor = .red
style.tintColor = .white
return style
}
...
}
2. Create NavigationBarTransitionController
Create NavigationBarTransitionController
instance and call navigationController(_:, willShow:, animated:)
method
//BaseNavigationController.swift
import BDNavigationBarTransition
class BaseNavigationController: UINavigationController, UINavigationControllerDelegate {
private let transitionController = NavigationBarTransitionController()
override func viewDidLoad() {
super.viewDidLoad()
// Set global default navigationbar style here
transitionController.defaultNavigationBarStyle = CommonNavigationBarStyle.customDefault
delegate = self
}
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
transitionController.navigationController(navigationController, willShow: viewController, animated: animated)
}
......
}
3. Implement CustomNavigationBar
protocol
// RedNaviBarViewController.swift
class RedNaviBarViewController: UIViewController, CustomNavigationBar {
var navigationBarStyle: NavigationBarStyleProtocol = CommonNavigationBarStyle.red
......
}
or
// RedNaviBarViewController.swift
extension RedNaviBarViewController: ViewControllerCustomNavigationBar {
var navigationBarStyle: NavigationBarStyleProtocol {
return CommonNavigationBarStyle.red
}
}
You can create your custom NavigationBarStyle by conforms to NavigationBarStyleProtocol
and implement refresh(_ navigationBar:, from:, to:)
method to decide how to display navigationBar
BDNavigationBarTransition is available under the MIT license. See the LICENSE file for more info.