MMNavigationController
A UINavigationController with fullscreen pop gesture. You can change color of navigation bar in a simple way!
Install / Use
/learn @MangoMade/MMNavigationControllerREADME
Requirements
- iOS 8.0
- Swift 4.0
- Swift 3.2请使用 0.0.5
Cocoapods
// Swift 4
pod 'MMNavigationController', '~> 0.1.0’
// Swift 3.2
pod 'MMNavigationController', '~> 0.0.5’
解决的问题
由于NavigationBar的生命周期是与UINavigationController绑定的,所以UINavigationController的所有子ViewController都共用同一个NavigationBar,但是在实际开发的需求中,常常会有某个视图的导航栏颜色与其它视图的导航栏颜色不同。
修改某一个viewController的颜色也不难:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.navigationBar.barTintColor = UIColor.blue
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.navigationBar.barTintColor = UIColor.white
}
只是每次需要这么多代码来解决一个看似很简单的问题,非常麻烦
使用MMNavigationController后只需要一句代码,即可修改导航栏颜色:
mm.navigationBarBackgroundColor = UIColor.blue
并且支持全屏Pop手势
效果图:

使用
由于Swift不能重写load方法,所以需要在AppDelegate中调用UIViewController.mm.load()
然后用MMNavigationController代替UINavigationController
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
/** 高亮 **/
UIViewController.mm.load()
let rootViewController = MMNavigationController(rootViewController: NormalViewController())
/** 高亮 **/
rootViewController.hideBottomLine()
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = rootViewController
window?.makeKeyAndVisible()
return true
}
之后就可以在ViewController的viewDidLoad中设置如下属性了:
override func viewDidLoad() {
super.viewDidLoad()
/// 修改当前ViewContoller的导航栏的背景颜色
mm.navigationBarBackgroundColor = UIColor.random
/// 修改当前ViewContoller标题颜色
mm.navigationBarTitleColor = UIColor.white
/// 隐藏当前ViewContoller的导航栏
mm.navigationBarHidden = true
/** 全屏手势相关属性 **/
/// pop 手势是否可用
mm.popGestrueEnable = false
/// pop 手势响应的范围
mm.popGestrueEnableWidth = 150
}
简单易用!
实现
主要实现是参考了FDFullscreenPopGesture
运用AOP, 在viewWillAppear中进行属性的设置。
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
