GithubHelp home page GithubHelp logo

littlema0404 / mmnavigationcontroller Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mangomade/mmnavigationcontroller

0.0 0.0 0.0 36 KB

A UINavigationController with fullscreen pop gesture. You can change color of navigation bar in a simple way!

License: MIT License

Ruby 4.68% Swift 93.11% Objective-C 2.21%

mmnavigationcontroller's Introduction

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手势

效果图:

2016-11-12 16_52_24.gif

使用

由于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
}

之后就可以在ViewControllerviewDidLoad中设置如下属性了:

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中进行属性的设置。

mmnavigationcontroller's People

Contributors

mangomade avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.