A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles

Overview

KMNavigationBarTransition 中文介绍

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles while pushing or popping a view controller for all orientations. And you don't need to write any line of code for it, it all happens automatically.

Screenshots

Now

KMNavigationBarTransition KMNavigationBarTransition

Before

KMNavigationBarTransition KMNavigationBarTransition

Introduction

The design concept of the library is that what you only need to care about is the background style of the navigation bar in the current view controller, without handling the various background styles while pushing or popping.

The library can capture the background style of the navigation bar in the disappearing view controller when pushing, and when you pop back to the view controller, the navigation bar will restore the previous style, so you don't need to consider the background style after popping. And you also don't need to consider it after pushing, because it is the view controller to be pushed that needs to be considered.

Usage

You don't need to import any header file when using this library, the library uses Method Swizzling to achieve the effect.

It is recommended to set the default background style of the navigation bar in the viewDidLoad method of the base view controller. When you need to change it, generally, you only need to do it in the viewDidLoad method of the current view controller, but if you need to support peek and pop on 3D Touch, you can do it in the viewWillAppear: method.

The following are some suggestions to set the background style of the navigation bar, and you can see the Example for details.

  • There are two methods to set the background style of the navigation bar, setBackgroundImage:forBarMetrics: and setBarTintColor:. It is recommended to use the former, you can see Known Issues for the details.

  • It is better not to change the value of the translucent property arbitrarily after initialization, otherwise the interface layout would be prone to confusion.

  • When the value of the translucent property is true, you can use the following mehod to make the navigation bar transparent:

    navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
    navigationController?.navigationBar.shadowImage = UIImage() // shadowImage is the 1px line
  • You can change the alpha value of the background color of the navigaiton bar by changing the alpha value of the image in the setBackgroundImage:forBarMetrics: method.

  • You can use the following method to show or hide the navigation bar in viewWillAppear::

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.setNavigationBarHidden(hidden, animated: animated)
    }

    You'd better not do it in neither viewWillDisappear: nor other methods performing transitions, because it is not easy to manage. Again, what you only need to care about is the style of the navigation bar in the current view controller.

    Of course, you'd better not hide the navigaion bar, it might triggers some apple's bug with interactive pop gesture.

Installation

CocoaPods

You can install the latest release version of CocoaPods with the following command:

$ gem install cocoapods

Simply add the following line to your Podfile:

pod 'KMNavigationBarTransition'

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate KMNavigationBarTransition into your Xcode project using Carthage, specify it in your Cartfile:

github "MoZhouqi/KMNavigationBarTransition"

Run carthage update to build the framework and drag the built KMNavigationBarTransition.framework into your Xcode project.

Requirements

  • iOS 7.0+

Known Issues

On iOS 8.2 or below, if you set the value of the translucent property to true and set the barTintColor for the background color, and then change the barTintColor, the background color of the navigation bar will flash when the interactive transition is cancelled.

To avoid this from happening, it is recommended to use setBackgroundImage:forBarMetrics: instead of setBarTintColor: to change the background color of the navigation bar.

License

KMNavigationBarTransition is released under the MIT license. See LICENSE for details.

Comments
  • push时,tabbar上移好像是在phoneX上运行就会出现

    push时,tabbar上移好像是在phoneX上运行就会出现

    push时候 tabbar会向上移动一段距离 好像并不是ios11系统问题 我拿6sp(ios11系统)手机运行工程 push不会出现。拿phoneX模拟器运行 push就会出现向上移动。 有个小猜测:1,可能是模拟器bug 2,phoneX中safeAreaInsets这个属性是不是在搞鬼的原因 https://www.lee1994.com/guan-yu-iphone/ 这里有个适配phoneX的小简介。希望楼主能把这个解决掉

    opened by fdyhgjg 16
  • presentViewController 出一个NavigationController 会有些问题...

    presentViewController 出一个NavigationController 会有些问题...

    71296364-05da-4cd0-86d6-716bf529a4c7 c51810be-eae2-4ca7-82ce-f7bcbcb3a128 如上图所示

    presentViewController 出导航控制器.. 导航控制器的RootViewController是 testViewController ,在testViewController的ViewDidLoad方法中 push到第二个控制器test2ViewController

    效果如下图所示... 导航栏的背景色会闪现出来...在不导入框架的时候是正常的..不知道面对这样的需求 有什么办法弄好... default

    opened by ClegeJJ 16
  • iOS 11 Compatibility

    iOS 11 Compatibility

    It seems that in the first iOS 11 beta, there were some major changes to UINavigationBars and how they worked. This results in some weird behavior after pushing view controllers...

    opened by inb4ohnoes 10
  • Convert to Swift 3.0 & Support Carthage

    Convert to Swift 3.0 & Support Carthage

    I'm using XCode 8.0 which make me force convert to swift 3.0.

    For carthage, dynamic framework only support iOS 8.0 and above. But this will not affect cocoapods version.

    Thanks for your awesome project.

    opened by tinpont 10
  • 滑动切换的时候不起作用

    滑动切换的时候不起作用

    我的页面刚进去的时候navigationBar是透明的我用

    self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
    self.navigationController?.navigationBar.shadowImage = UIImage()
    

    然后随着滚动到一定的位置就改变为显示

    self.navigationController?.navigationBar.setBackgroundImage(nil, forBarMetrics: UIBarMetrics.Default)
    self.navigationController?.navigationBar.shadowImage = nil
    

    但是不起作用,我移除这个库就有作用了,我轻轻的滑动返回一点然后继续停在这个页面,又可以其作用了。不知道为啥。麻烦看下

    opened by smalldu 9
  • Fix the issue of km_resizeTransitionNavigationBarFrame when the view …

    Fix the issue of km_resizeTransitionNavigationBarFrame when the view …

    If the current view is UIScrollView, when km_resizeTransitionNavigationBarFrame is called, the scrollview's content offset may not be finalized (For example, if you try to to drag the scrollview hardly and swipe to dismiss the current view controller immediately), in this case the position of the navigation bar will be wrong.

    The fix here is to change the scrollview's content offset to the final value if it's invalid.

    Before this fix: break2

    After this fix: after2

    opened by flexme 8
  • iOS 11 Support shifts off background of navigation bar

    iOS 11 Support shifts off background of navigation bar

    As mentioned in issue https://github.com/MoZhouqi/KMNavigationBarTransition/issues/69 navigation bar background shifts off (i guess the side of status bar). It happens when performing push, pop or interactive pop. P.S.> this behaviour is only occurs when navigation bar's translucent property is set to false Screenshot: img_0367

    opened by Pratik948 7
  • 导航栏背景颜色会闪一下

    导航栏背景颜色会闪一下

    为什么我遇到的和你说的已知问题是反的,使用 setBarTintColor 设置背景颜色不会出现闪一下的问题,使用 setBackgroundImage: forBarMetrics: 方法设置背景颜色,每次 push 一个页面,导航栏背景都会轻微的闪一下,以上情况都发生在 translucentYES 的时候,translucentNO 的时候不会有上述问题,但是页面会整体下移一个导航栏的高度,求解决办法...

    opened by karise-guo 6
  • ContainerView is changing to white during tranistion

    ContainerView is changing to white during tranistion

    Hi, i presented view controller using blur effect on background, so i wanted to all view controllers have clearColor, during - (void)km_viewWillLayoutSubviews { you are setting containerView to background color and my presented controllers looks ugly, do you really need to set background color to white color?

    opened by m1entus 6
  • 页面间NavigationBar透明与不透明之间切换的BUG

    页面间NavigationBar透明与不透明之间切换的BUG

    iOS 10.0.1 我创建了三个ViewController,第一个不透明 第二个透明 第三个不透明 viewController1 -》 viewController2 -》 viewController3(此时ViewController2的navigation bar只显示44像素的颜色) 然后返回顺序 viewController3 -》viewController2 -》viewController1(此时ViewController1也只显示44像素)

    opened by 393385724 5
  • km_containerViewBackgroundColor adds white line during animation

    km_containerViewBackgroundColor adds white line during animation

    Can we make km_containerViewBackgroundColor as associated property to allow users to customize background color. I have black controller and during custom animation appears white lines. Can prepare PR if needed

    opened by Igor-Palaguta 5
  • iOS15导航栏标题样式异常

    iOS15导航栏标题样式异常

    https://user-images.githubusercontent.com/9626353/188072374-50a7fc79-1cc3-4f21-a984-748be9f4e9c3.MP4

    A页面隐藏导航栏,跳转未隐藏导航栏的B页面,侧滑返回时,B页面导航标题字体样式会改变为A页面的默认值,松开手指则复原为自定义状态。

    opened by GUIYIVIEW 0
  • navigationBar.isTranslucent = true,页面背景色不同时跳转,会有闪烁

    navigationBar.isTranslucent = true,页面背景色不同时跳转,会有闪烁

    测试前提条件: 1、navigationBar.isTranslucent = true 2、导航栏背景色设置为 navigationController?.navigationBar.barTintColor = .white 或者 navigationController?.navigationBar.setBackgroundImage(UIColor.white.toUIImage(), for: .default)。其他颜色也可以如 UIColor.cyan 3、页面背景色设置为和导航栏不同的颜色,如绿色 现象是,push过程中导航栏颜色是 isTranslucent = false 的状态,push完成时瞬间变成透明的

    opened by yuanyedehuhuan 2
  • navigationController?.navigationBar.shadowImage 设置异常失效

    navigationController?.navigationBar.shadowImage 设置异常失效

    在demo中测试,第一个页面(Title 1)在 viewDidLoad 中设置为 navigationController?.navigationBar.shadowImage = UIImage(),即隐藏导航栏横线。第二个页面(Title 2)在 viewDidLoad 中设置为 navigationController?.navigationBar.shadowImage = nil,即显示导航栏横线。

    设置完毕,点击从 Title 1 跳转到 Title 2,会出现横线显示异常,push过程中横线是显示的,当跳转完成时横线消失,之后无论怎么设置都不好使了。

    经过测试,发现需要保证第一个页面显示横线,或者至少保证在 viewDidAppear 之前显示横线,如果需要第一个页面隐藏横线,就在 viewDidAppear 中设置 navigationController?.navigationBar.shadowImage = UIImage()。只有这样后续操作才能正常。

    opened by yuanyedehuhuan 2
  • KMNavigationBarTransition 与 转场框架 Hero 冲突

    KMNavigationBarTransition 与 转场框架 Hero 冲突

    Bug 表现 项目中使用KMNavigationBarTransition来实现导航栏的平滑过渡,现在新添加了Hero框架来实现转场动画,但是会影响到KMNavigationBarTransition,在pushpop中出现黑色 Hero框架使用的人还是蛮多的 不知道大佬有没有时间去瞧一瞧,能不能兼容下

    截图 转场过程中导航栏显示黑色

    如何重现 如有需要我可以上传demo至github

    预期的表现

    其他信息

    • 设备: [例如模拟器、iPhone、iPad]
    • iOS 版本: [iOS 13.x]
    • Xcode 版本: [Xcode 11.x]
    opened by iBinbro 5
Owner
Zhouqi Mo
Zhouqi Mo
Change SwiftUI Navigation Bar Color for different View

SwiftUINavigationBarColor Change SwiftUI NavigationBar background color per screen. Usage For NavigationBarColor to work, you have to set the Navigati

Hai Feng Kao 18 Jul 15, 2022
SwiftUINavigator: a lightweight, flexible, and super easy library which makes SwiftUI navigation a trivial task

The logo is contributed with ❤️ by Mahmoud Hussein SwiftUINavigator is a lightwe

OpenBytes 22 Dec 21, 2022
Easily hide and show a view controller's navigation bar (and tab bar) as a user scrolls

HidingNavigationBar An easy to use library (written in Swift) that manages hiding and showing a navigation bar as a user scrolls. Features Usage Custo

Tristan Himmelman 1k Dec 21, 2022
A wrapper for NavigationView and NavigationLink that makes programmatic navigation a little friendlier.

NavigatorKit A wrapper for NavigationView and NavigationLink that makes programmatic navigation a little friendlier. NavigatorKit is an opinionated wr

Gyuri Grell 2 Jun 16, 2022
Simple and integrated way to customize navigation bar experience on iOS app.

NavKit Simple and integrated way to customize navigation bar experience on iOS app. It should save our time that we usually use to make abstraction of

Wilbert Liu 37 Dec 7, 2022
Simple custom navigation bar by swift

YoNavBarView Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation YoNav

null 1 Nov 23, 2021
Replicating the 'clear' navigation bar style of the iOS 12 Apple TV app.

TONavigationBar TONavigationBar is an open-source subclass of UINavigationBar that adds the ability to set the background content of the navigation ba

Tim Oliver 247 Dec 7, 2022
FlowStacks allows you to hoist SwiftUI navigation and presentation state into a Coordinator

FlowStacks allow you to manage complex SwiftUI navigation and presentation flows with a single piece of state. This makes it easy to hoist that state into a high-level coordinator view. Using this pattern, you can write isolated views that have zero knowledge of their context within the navigation flow of an app.

John Patrick Morgan 471 Jan 3, 2023
Tools for making SwiftUI navigation simpler, more ergonomic and more precise.

SwiftUI Navigation Tools for making SwiftUI navigation simpler, more ergonomic and more precise. Motivation Tools Navigation overloads Navigation view

Point-Free 1.1k Jan 1, 2023
Models UI navigation patterns using TCA

Composable Navigation The Composable Navigation is a Swift Package that builds on top of The Composable Architecture (TCA, for short). It models UI na

Michael Heinzl 41 Dec 14, 2022
sRouting - The lightweight navigation framework for SwiftUI.

sRouting The lightweight navigation framework for SwiftUI. Overview sRouting using the native navigation mechanism in SwiftUI. It's easy to handle nav

Shiro 8 Aug 15, 2022
An iOS view-controller navigation management. No inherit, using one line code to integrate.

KGNavigationBar Example An iOS view-controller navigation management. No inherit, using one line code to integrate. 一个 iOS 控制器导航管理库. 无需继承, 一行代码即可实现集成。

VanJay 5 Sep 6, 2021
🧭 SwiftUI navigation done right

?? NavigationKit NavigationKit is a lightweight library which makes SwiftUI navigation super easy to use. ?? Installation ?? Swift Package Manager Usi

Alex Nagy 152 Dec 27, 2022
Navigation helpers for SwiftUI applications build with ComposableArchitecture

Swift Composable Presentation ?? Description Navigation helpers for SwiftUI applications build with ComposableArchitecture. More info about the concep

Dariusz Rybicki 52 Dec 14, 2022
Powerful navigation in the Composable Architecture via the coordinator pattern

TCACoordinators The coordinator pattern in the Composable Architecture TCACoordinators brings a flexible approach to navigation in SwiftUI using the C

John Patrick Morgan 231 Jan 7, 2023
Cordova/Phonegap plugin for launching today's most popular navigation/ride apps to navigate to a destination.

Launch Navigator Cordova/Phonegap Plugin Cordova/Phonegap plugin for launching today's most popular navigation/ride apps to navigate to a destination.

null 0 Oct 25, 2021
Make SwiftUI Navigation be easy

VNavigator VNavigator is a clean and easy-to-use navigation in SwiftUI base on UINavigationController in UIKit Installation From CocoaPods CocoaPods i

Vu Vuong 10 Dec 6, 2022
SwiftUINavigation provides UIKit-like navigation in SwiftUI

SwiftUINavigation About SwiftUINavigation provides UIKit-like navigation in Swif

Bhimsen Padalkar 1 Mar 28, 2022
A lightweight iOS mini framework that enables programmatic navigation with SwiftUI, by using UIKit under the hood.

RouteLinkKit A lightweight iOS mini framework that enables programmatic navigation with SwiftUI. RouteLinkKit is fully compatible with native Navigati

Αθανάσιος Κεφαλάς 4 Feb 8, 2022