Replicating the 'clear' navigation bar style of the iOS 12 Apple TV app.

Overview

TONavigationBar

Version GitHub license Platform Beerpay PayPal

TONavigationBar is an open-source subclass of UINavigationBar that adds the ability to set the background content of the navigation bar to transparent, and then gradually bring it back in as the user scrolls through the page.

Apple uses this effect in their 'modern' style iOS apps (Music, TV, App Store) for any content deemed 'notable'. Unfortunately, while it seems like a trivial thing to be able to do, none of the APIs necessary to reconfigure a UINavigationBar to be transparent in that way exist. TONavigationBar internally re-implements a variety of the UINavigationBar functionality in order to make this possible.

Features

  • Fully integrates into UINavigationController.
  • Participates in UINavigationController's 'swipe-to-go-back' gesture.
  • Supports light and dark themed apps.
  • Features an animation to restore to the normal UINavigationBar appearance.
  • A target UIScrollView may be specified in order to avoid having to manually pass information to the bar.
  • Library also features TOHeaderImageView, a header view that may be used as the banner in scroll views.

System Requirements

iOS 11.0 or above

Installation

As a CocoaPods Dependency

Objective-C

Add the following to your Podfile:

pod 'TONavigationBar'

Manual Installation

All of the necessary source files are in the TONavigationBar, folder. Simply copy that folder to your Xcode project and import all of the files in it.

Examples

TONavigationBar has been designed to be as hands-off as possible. It integrates with UINavigationController and only needs to be interacted with when changing the visibility of the background content.

Basic Implementation

Integrating with UINavigationController

#import "TONavigationBar.h"

UINavigationController *navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[TONavigationBar class] toolbarClass:nil];

Showing and Hiding the Background Content

#import "TONavigationBar.h"

@implementation MyViewController // A child of the `UINavigationController` stack

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController.to_navigationBar setBackgroundHidden:YES animated:animated forViewController:self];
    [self.navigationController.to_navigationBar setTargetScrollView:self.tableView minimumOffset:200.0f]; // 200.0f is the height of the header view
}

@end

Creating and Configuring a Header View

#import "TOHeaderImageView.h"

@interface MyTableViewController () <UIScrollViewDelegate>

@property (nonatomic, strong) TOHeaderImageView *headerView;

@end

@implementation MyTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
	
    self.headerView = [[TOHeaderImageView alloc] initWithImage:[UIImage imageNamed:@"MyPicture.jpg"] height:200.0f];
    self.headerView.shadowHidden = NO;
    self.tableView.tableHeaderView = self.headerView;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.headerView.scrollOffset = scrollView.contentOffset.y;
}

@end

Architecture of TONavigationBar

In order to modify UINavigationBar to the same style Apple uses, a few things need to happen:

  • The background view, including the separator line need to be removed.
  • The title label in the center needs to be removed.
  • The tint color needs to be set to white (To make the buttons white).
  • The bar style needs to be set to UIBarStyleBlack (Which makes UINavigationController change the status bar style to white.)

Changing the tint color and bar style are trivial, however there are no public APIs provided by Apple to easily control the alpha of just the background views, or the title label.

The way TONavigationBar solves this is as follows:

  • The official background views are removed by using [UINavigationBar setBackgroundImage:[[UIImage alloc] init] and then a wholly custom set are put in their place. This also means transitioning it back while scrolling is possible.
  • The title label is controlled by manually traversing UINavigationBar's internal views, finding the right one, and then overriding its presentation by Apple's code.

Is this App Store safe?

Yes. It should be. The only slightly dubious thing this view does is that it traverses some internal Apple views to find the title label. However no private APIs are called in the process, so that should be no problem.

That being said, internal view traversal is always a terrible way to go, and this library MAY break in future versions of iOS without maintenance. Thankfully, it's set up so if it does break, the absolute worst thing that can happen is that the title label will always be visible.

Credits

TONavigationBar was originally created by Tim Oliver as a component for iComics, a comic reader app for iOS.

Firewatch Wallpaper by Campo Santo and is used for illustrative purposes. Firewatch is available on Steam.

iOS Device mockups used in the screenshot created by Pixeden.

License

TONavigationBar is licensed under the MIT License, please see the LICENSE file. analytics

Comments
  • Swift Version?

    Swift Version?

    Is it possible to re create this in swift if I just follow your code? You said you used some internal Apple code which must be in Obj C. Right? So is it possible to re create in Swift?

    opened by anmolmalhotra 2
  • New logo / icon

    New logo / icon

    Hi, I am a graphic designer, I want to help others in graphic design.

    After I reviewed your project, you have no logo on this project. Therefore I want to contribute to this project by creating a new logo / icon. what do you think?

    opened by mansya 1
  • Changing the back button tint colour on scroll

    Changing the back button tint colour on scroll

    Hi @TimOliver,

    I've been looking through the code in TONavigationBar.m to and was wondering whether it's possible to change the back button tint colour when the header image is visible, versus when the navigation bar is visible?

    Potentially using something like the following: [self.topItem.backBarButtonItem setTintColor:[UIColor yellowColor]];

    The idea is for the back button to be yellow when header image is visible, but turn to red when the navigation bar is visible, and vice versa.

    Would you have any suggestions on whether it's possible?

    opened by dandelgrosso 0
  • Unexpected behavior when initialized from a Storyboard

    Unexpected behavior when initialized from a Storyboard

    TONavigationBar doesn't work as expected when initialized from a Storyboard file.

    To initialize TONavigationBar from Storyboard, select navigation bar on a UINavigationController and set its custom class to TONavigationBar.

    opened by gbmksquare 0
  • to_navigationBar is nil but navigationBar is not?

    to_navigationBar is nil but navigationBar is not?

    I encountered a problem with this framework, I might be using it wrong somehow but I followed the instructions. I create my navigation controller like this:

    self.rootViewController = UINavigationController(navigationBarClass: TONavigationBar.self, toolbarClass: nil) I'm using the Coordinator patter here so rootViewController is declared as var rootViewController: UINavigationController

    In my detail view controller the navigation bar does not hide, the console output is quite strange, see for yourself

    Zrzut ekranu 2019-07-02 o 07 44 40 bug 
    opened by wiencheck 5
  • Tint color transition animation slightly broken in iOS 12

    Tint color transition animation slightly broken in iOS 12

    broken

    When manually swiping to go back, the title text colour of the "Back" item instantly changes to the final value.

    This seems to be a system level regression in iOS 12, as the similar effects in Music, TV, and the App Store are all exhibiting the same behaviour.

    I tried several ways to try and "force" the transition, including manually calculating and setting an interpolated colour on each frame tick, but none of these worked particularly well.

    I'm going to file a radar, and hopefully it will be fixed in a future version of iOS 12.

    bug 
    opened by TimOliver 0
  • Support barTintColor and tintColor

    Support barTintColor and tintColor

    UINavigationBar can set barTintColor property to change the color of navigation bar for better appearance or branding (e.g. Facebook). TONavigationBar currently only supports white and black bar style, so its color may not match with other views where plain UINavigationBar with bar tint color is used.

    question 
    opened by gbmksquare 3
  • Support iOS 10 properly

    Support iOS 10 properly

    For the time being, I've had to raise the minimum requirements to iOS 11.

    It turns out that UINavigationBar was drastically changed in iOS 11. Before that, there was no UINavigationItemContentView that could be conveniently hooked.

    Unfortunately, initial tests with iOS 10 seemed to indicate that it's not easy to isolate the title label and suppress it for the opening transition.

    I'd like to play with it more when I get the time, but since iOS 10 will be deprecated once iOS 12 hits, it might not be worth the effort.

    bug 
    opened by TimOliver 0
Owner
Tim Oliver
Gamer. Developer. Geek. Senior Software Engineer at @Drivemode (prev. @Realm). Lover of writing iOS code and singer of bad karaoke. 日本語もオッケ〜
Tim Oliver
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
An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations and programmatic navigation.

swiftui-navigation-stack An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations

Matteo 753 Jan 2, 2023
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
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
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
Simple iOS app to showcase navigation with coordinators in SwiftUI + MVVM.

SimpleNavigation Simple iOS app to showcase the use of the Coordinator pattern using SwiftUI and MVVM. The implementation is as easy as calling a push

Erik Lopez 7 Dec 6, 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
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
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
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
🧭 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
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
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
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
SwiftUINavigation provides UIKit-like navigation in SwiftUI

SwiftUINavigation About SwiftUINavigation provides UIKit-like navigation in Swif

Bhimsen Padalkar 1 Mar 28, 2022