NavigationBarHelper

master

A library that helps to manage the navigation bar style. It helps to remember bar attributes between different VCs and keep the transition smooth.
Jerry0523/NavigationBarHelper

Build Status

NavigationBarHelper

A library that helps to manage the navigation bar style. It helps to remember bar attributes between different VCs and keep the transition smooth.

alt tag

Usage

When your app finishes launch, call the function below to start up the helper.

NavigationBarHelper.load()

swizzle UIViewController.viewSafeAreaInsetsDidChange

swizzle UIViewController.viewWillLayoutSubviews

swizzle UIViewController.viewWillAppear(_:)

UINavigationBar.hitTest(_:with:)

For a viewController, use the function below to modify the navigation bar.

override func viewDidLoad() {
    super.viewDidLoad()
    barBackgroundHelper.perform {
        //Codes for navigation bar update.
        //e.g. $0.tintColor = UIColor.white
    }
}

After calling the function above, any attribute (background image/tintColor/barTintColor/barStyle etc) will be remembered by the library. It will create a mirror background view of the navigation bar (auto managed) and clear the bar background (to provide a smooth transition). Any change to the navigation bar background (background image/barTintColor/barStyle/shadowImage) in the closure will be syncronized with the mirror view.

Protocol NavigationBarHelperDelegate

  • willRestore(backgroundAttr: inout NavigationBarHelper.BackgroundAttr)

Called before the mirror view capturing the bar's background attribute. Modify the backgroundAttr if it is not your appetite.

  • didRestore(backgroundAttr: NavigationBarHelper.BackgroundAttr)

Called after the mirror view capturing the bar's background attribute. It is the best time for you to do additional change to the bar's background attr. After this function is called, the mirror background view will synchronize with the bar's background.

  • willRestore(foregroundAttr: inout NavigationBarHelper.ForegroundAttr)

Called before the navigation bar's foreground attribute being restored, especially when the viewController's appearing. Modify the foregroundAttr if it is not your appetite.

  • didRestore(foregroundAttr: NavigationBarHelper.ForegroundAttr)

Called after the navigation bar's foreground attribute being restored, especially when the viewController's appearing. Do additional change if you have modified the navigation bar out of the performNavigationBarUpdates scope.(e.g, you have set the bar tint color according to scrollview offset).

License

(MIT license)

Description

  • Swift Tools 5.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Wed Mar 20 2024 22:51:09 GMT-0900 (Hawaii-Aleutian Daylight Time)