[03] it iOS development < JKNavigationController> set free navigation bar navigationBar transparency, color

2 edition: JKNavigationController

Although the use of UINavigationBar+JKTransparentize.m in the KVC call private API, but has been through the shelf audit, will not affect the audit. I would also like to welcome all of you together to optimize this small framework.

Design sketch

[03] it iOS development < JKNavigationController> set free navigation bar navigationBar transparency, color

  • The 1 version is only to achieve a modified NavigationBar (color) transparency, compatibility with the BUG on the iOS10, and there is no adaptation Push/Pop switch animation.
  • 2 version is compatible with iOS8, iOS9, iOS10, an increase of Push and Pop animation compatibility, and increase the full screen side row return function. In the implementation of the reference Leo LTNavigationBar, SunnyDog FDFullscreenPopGesture and JNTian JTNavigationController. The 2 version of JKNavigationController can be viewed as a combinatorial library of 3 third party libraries (components).
  • 2.1: increase the return button to click on the interception of events.

Realization principle

Multi style controller switching function realization rendering in its principle, can see the “navigation controller switching effect” NetEase cloud music by Reveal analysis, the idea is JNTian JTNavigationController, I also refer to the author’s ideas, and then made a few changes, introduced 2 other libraries function.


#import "JKNavigationController.h"

JKNavigationController.h includes 4 classes of files:

The background color changes navigationBar UINavigationBar+JKTransparentize.h (transparency)
“JKPackageNavigationController.h” style navigation controller switching effect of
“switch screen sideslip gesture JKBackIndicatorButton.h custom back button

Set the global background color of navigationController.navigationBar, will affect the subsequent Push toVC.navigationController.navigationBar background color.

Self.navigationController.navigationBar.jk_barBackgroundColor = [UIColor orangeColor];

Set the current controller vc.navigationController.navigationBar the background color, can be realized by this method in the navigationBar controller, color transparent effect:
can not see the picture of the stamp here

[03] it iOS development < JKNavigationController> set free navigation bar navigationBar transparency, color
[self.navigationController.navigationBar jk_setNavigationBarBackgroundColor:[UIColor orangeColor]];

The control of the global full screen sideslip return gesture switch will affect the subsequent Push of the toVC jk_fullScreenPopGestrueEnabled

Self.jk_rootNavigationController.jk_fullScreenPopGestrueEnabled = YES;

Control of the local controller of the full screen sideslip return gesture switch, you need to pay attention to the closure of the full screen sideslip gestures, the system will be used to return to the original sideslip.

Self.jk_fullScreenPopGestrueEnabled = NO;

If you need to intercept the return button click event, the controller can be achieved in the JKNavigationControllerDelegate protocol

- (BOOL) jk_navigationController: (JKRootNavigationController *) navigationController shouldPopItem: (UINavigationItem *) item {do something}...

If you have a custom return button JKBackIndicatorButton controller, it is recommended to use the following method to modify the navigationBar.tintColor, the interior will redraw the picture.

[self.navigationController.navigationBar jk_setTintColor:[UIColor purpleColor]]; / / self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

If you want to realize the effect of almost daily home page, that is, the gradual migration of the effect of NavigationBar, then call the following code.
can’t see the picture stamp here

[03] it iOS development < JKNavigationController> set free navigation bar navigationBar transparency, color
[navigationBar jk_setNavigationBarVerticalOffsetY: (CGFloat) offsetY] / / / gradient transparency by calling jk_setNavigationBarSubViewsAlpha: (CGFloat) alpha

About Push + toVC.hidesBottomBarWhenPushed = YES animation or blank flashing, actually with AutoLayout constraint update timing, so we should choose the appropriate reference to Bottom TableView constraints, when necessary to set toVC.automaticallyAdjustsScrollViewInsets = NO, please look at the picture below.
seems to be linked to the picture, poke here

[03] it iOS development < JKNavigationController> set free navigation bar navigationBar transparency, color


Split line, the following content is for the 1 version, you can look at.


1 version, there are a lot of BUG

Some time ago it under the transparent navigation bar, try the 3 methods for setting the navigationBar color and transparency. 3 ideas are set by setting the alpha value of the background color to achieve transparency, rather than set the way to achieve transparency. As follows:
[03] it iOS development < JKNavigationController> set free navigation bar navigationBar transparency, color
renderings renderings first understand the navigationBar view, leftBarButtonItem and rightBarButtonItem in the case of a print navigationBar.subviews class name. From the print results to the top is that the default return button, the middle is leftBarButtonItem/rightBarButtonItem, the bottom of the view class named _UINavigationBarBackground as the name suggests, can guess useful, which determines the navigationBar background image or color. 2016-01-28 14:59:05.563[8091:2790630] _UINavigationBarBackground – the bottom of the background layer, determine the color and background image 2016-01-28 14:59:05.564[8091:2790630] UINavigationButton —-leftBarButtonItem/rightBarButtonItem 2016-01-28 14:59:05.564[8091:2790630] UINavigationButton —-leftBarButtonItem/rightBarButtonItem 2016-01-28 14:59:05.564[8091:2790630] _UINavigationBarBackIndicatorView —-BackIndicatorView 3 come to talk about my ideas directly out of the bottom class named _UINavigationBarBackIndicatorView view, and then set the background color. The height of navigationBar is only 44, you can add a height of 20 view, placed in the status bar below, set the background color with navigationBar. The original _UINavigationBarBackIndicatorView transparent, and then insert a height of 64 at the bottom of the view, and then set the background color. The premise of the 3 ideas
first let navigationBar transparent, and then set the transparency. Apple did not disclose this member attributes, but provides a way to set the background image, the privacy of _UINavigationBarBackIndicatorView should inherit UIImageView. [navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; the way to the bottom line of setShadowImage:[UIImage transparent [navigationBar new]]; 1
method is simple and crude, the background bottom out set the background color. However, it may be related to the private property, there will be a shelf risk, not recommended. UIView * firstView = [self.navigationController.navigationBar.subviews firstObject] = [[UIColor; firstView.backgroundColor redColor]colorWithAlphaComponent:0.3];
navigationBar thought 2 height is only 44, if the whole transparent directly set the background color, will find the status bar below is transparent, so the need to add a view on the bottom bar, and then set the background color. This method is flexible, not only can be used to set the transparency can also be used for navigationBar offset, such as know the effect of almost daily home page. [self.navigationController.navigationBar setBackgroundColor:[[UIColor lightGrayColor] colorWithAlphaComponent:0.3]]; UIView statusBarView = [[UIView * alloc]initWithFrame:CGRectMake (0, -20, [UIScreen, mainScreen].bounds.size.width, 20); statusBarView.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.3]; [self.navigationController.navigationBar addSubview:statusBarView]; 3 thought
transparent, you can insert a view view navigationBar as background, the height of 64. There is also a key point, userInteractionEnabled must be NO, or after the jump page can not click leftBarButtonItem/rightBarButtonItem. I do not know why to close the interaction, but the pit pit was miserable, and finally found a transparent navigation bar in demo GitHub to solve this problem. This method also some pits, such as the view must be inserted into the Index = 0 position, that is, the bottom, or jump the page will be replaced by the location of the system, there are some problems. UIView * barBackgroundView [[UIView = alloc]init]; barBackgroundView.tag = 100; barBackgroundView.frame = CGRectMake (0, -20, [UIScreen, mainScreen].bounds.size.width, 64); barBackgroundView.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.3]; [self.navigationController.navigationBar insertSubview:barBackgroundView atIndex:0]; barBackgroundView.userInteractionEnabled = NO; / / key ideas 4, recommendation third party
has a good package set navigationBar classification for transparency. Is the third kind of method, the above third kinds of ideas in closed userInteractionEnabled is found in the Demo. GitHub transfer gate.

This article uses the Demo, made a wheel