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
SwiftUI view enabling navigation between pages of content, imitating the behaviour of UIPageViewController for iOS and watchOS

PageView SwiftUI view enabling page-based navigation, imitating the behaviour of UIPageViewController in iOS. Why SwiftUI doesn't have any kind of pag

Kacper Rączy 365 Dec 29, 2022
A custom UIControl which functions like UISlider where you can set multiple intervals with different step values for each interval.

MultiStepSlider A custom UIControl which functions like UISlider where you can set multiple intervals with different step values for each interval. Th

Susmita Horrow 25 Apr 28, 2022
A library, which adds the ability to hide navigation bar when view controller is pushed via hidesNavigationBarWhenPushed flag

HidesNavigationBarWhenPushed A library, which adds the ability to hide navigation bar when view controller is pushed via hidesNavigationBarWhenPushed

Danil Gontovnik 55 Oct 19, 2022
Wallet is a library to manage cards and passes.

Wallet Wallet is a replica of the Apple's Wallet interface. Add, delete or present your cards and passes. Feel free to use this pod in your project an

Russ St Amant 360 Feb 4, 2022
A library to recreate the iOS Apple Music now playing transition

DeckTransition DeckTransition is an attempt to recreate the card-like transition found in the iOS 10 Apple Music and iMessage apps. Hereʼs a GIF showi

Harshil Shah 2.2k Dec 15, 2022
A framework which helps you attach observers to `UIView`s to get updates on its frame changes

FrameObserver is a framework that lets you attach observers to any UIView subclass and get notified when its size changes. It doesn't use any Method S

null 11 Jul 25, 2022
Fashion is your helper to share and reuse UI styles in a Swifty way.

Fashion is your helper to share and reuse UI styles in a Swifty way. The main goal is not to style your native apps in CSS, but use a set

Vadym Markov 124 Nov 20, 2022
An iOS Library that makes shadows management easy on UIView.

ShadowView is an iOS Shadow library that makes view's shadow implementation easy and sweet ?? ?? . Add simple shadows to add a gaussian blurred projec

Pierre 404 Dec 8, 2022
AGCircularPicker is helpful component for creating a controller aimed to manage any calculated parameter

We are pleased to offer you our new free lightweight plugin named AGCircularPicker. AGCircularPicker is helpful for creating a controller aimed to man

Agilie Team 617 Dec 19, 2022
Advanced List View for SwiftUI with pagination & different states

AdvancedList This package provides a wrapper view around the SwiftUI List view which adds pagination (through my ListPagination package) and an empty,

Chris 246 Jan 3, 2023
Demonstrate the toolbar view modifier for SwiftUI with different placements

ToolbarProject Demonstrate the toolbar view modifier for SwiftUI with different placements Youtube tutorial --> https://youtu.be/jTW5Z-kyL8g Use toolb

Karin Prater 2 Mar 24, 2022
A little app which shows different ways to simulate NSPanel using NSWindow

FunWithPanels A little app which shows different ways to simulate NSPanel using NSWindow, for better or worse. Settings FunWithPanels uses a combinati

Mitchell Cohen 7 Aug 3, 2022
A few drop-in SwiftUI components for easily importing and thumb-nailing files

FilesUI A few drop-in SwiftUI components for easily importing and thumb-nailing files Usage 1. Import Files To import files you can use the FileImport

Brianna Zamora 3 Oct 19, 2022
Easily add drop shadows, borders, and round corners to a UIView.

Easily add drop shadows, borders, rounded corners to a UIView. Installation CocoaPods Add the follwing to your Podfile: pod 'Shades' Usage Storyboard

Aaron Sutton 14 Jun 20, 2020
Anchorage - Single file UIView drag and drop system

anchorage Single file UIView drag and drop system anchors.mp4 License Copyright

● ●●   ● 3 Jan 28, 2022
A Material Design drop down for iOS

A Material Design drop down for iOS written in Swift. Demo Do pod try DropDown in your console and run the project to try a demo. To install CocoaPods

AssistoLab 2.3k Dec 20, 2022
Newly is a drop in solution to add Twitter/Facebook/Linkedin style, new updates/tweets/posts available button

Newly is a drop in solution to add Twitter/Facebook/Linkedin style, new updates/tweets/posts available button. It can be used to notify user about new content availability and can other actions can be triggers using its delegate method.

Dhiraj Rajendra Jadhao 197 Sep 22, 2022
A child view controller framework that makes setting up your parent controllers as easy as pie.

Description Family is a child view controller framework that makes setting up your parent controllers as easy as pie. With a simple yet powerful publi

Christoffer Winterkvist 246 Dec 28, 2022
Windless makes it easy to implement invisible layout loading view.

Windless Windless makes it easy to implement invisible layout loading view. Contents Requirements Installation Usage Looks Credits Communication Licen

ArLupin 940 Dec 22, 2022