Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I think should support to navigationBar.tintColor , navigationBar.titleTextAttributes, #125

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ - (UIViewController *)km_popViewControllerAnimated:(BOOL)animated {
UIViewController *appearingViewController = self.viewControllers[self.viewControllers.count - 2];
if (appearingViewController.km_transitionNavigationBar) {
UINavigationBar *appearingNavigationBar = appearingViewController.km_transitionNavigationBar;
self.navigationBar.barTintColor = appearingNavigationBar.barTintColor;
[self.navigationBar setBackgroundImage:[appearingNavigationBar backgroundImageForBarMetrics:UIBarMetricsDefault] forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = appearingNavigationBar.shadowImage;
[self km_settingNavigationBarMoreProperty:appearingNavigationBar];
}
if (animated) {
disappearingViewController.navigationController.km_backgroundViewHidden = YES;
Expand All @@ -109,9 +107,8 @@ - (UIViewController *)km_popViewControllerAnimated:(BOOL)animated {
[disappearingViewController km_addTransitionNavigationBarIfNeeded];
if (viewController.km_transitionNavigationBar) {
UINavigationBar *appearingNavigationBar = viewController.km_transitionNavigationBar;
self.navigationBar.barTintColor = appearingNavigationBar.barTintColor;
[self.navigationBar setBackgroundImage:[appearingNavigationBar backgroundImageForBarMetrics:UIBarMetricsDefault] forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = appearingNavigationBar.shadowImage;

[self km_settingNavigationBarMoreProperty:appearingNavigationBar];
}
if (animated) {
disappearingViewController.navigationController.km_backgroundViewHidden = YES;
Expand All @@ -128,9 +125,8 @@ - (UIViewController *)km_popViewControllerAnimated:(BOOL)animated {
UIViewController *rootViewController = self.viewControllers.firstObject;
if (rootViewController.km_transitionNavigationBar) {
UINavigationBar *appearingNavigationBar = rootViewController.km_transitionNavigationBar;
self.navigationBar.barTintColor = appearingNavigationBar.barTintColor;
[self.navigationBar setBackgroundImage:[appearingNavigationBar backgroundImageForBarMetrics:UIBarMetricsDefault] forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = appearingNavigationBar.shadowImage;

[self km_settingNavigationBarMoreProperty:appearingNavigationBar];
}
if (animated) {
disappearingViewController.navigationController.km_backgroundViewHidden = YES;
Expand All @@ -149,6 +145,15 @@ - (void)km_setViewControllers:(NSArray<UIViewController *> *)viewControllers ani
return [self km_setViewControllers:viewControllers animated:animated];
}

- (void)km_settingNavigationBarMoreProperty:(UINavigationBar *)appearingNavigationBar{
self.navigationBar.barTintColor = appearingNavigationBar.barTintColor;
[self.navigationBar setBackgroundImage:[appearingNavigationBar backgroundImageForBarMetrics:UIBarMetricsDefault] forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = appearingNavigationBar.shadowImage;

self.navigationBar.tintColor = appearingNavigationBar.tintColor;
self.navigationBar.titleTextAttributes = appearingNavigationBar.titleTextAttributes;
}

- (BOOL)km_backgroundViewHidden {
return [objc_getAssociatedObject(self, _cmd) boolValue];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,38 @@ - (void)km_viewWillAppear:(BOOL)animated {
}
}

- (void)km_settingNavigationBarMoreProperty:(UINavigationBar *)bar{
//revoke navigationBar
return [self km_settingNavigationBarFrom:bar toBar:self.navigationController.navigationBar];
}

- (void)km_settingNavigationBarFrom:(UINavigationBar *)fromBar toBar:(UINavigationBar *)toBar{
toBar.barStyle = fromBar.barStyle;
toBar.barTintColor = fromBar.barTintColor;
[toBar setBackgroundImage:[fromBar backgroundImageForBarMetrics:UIBarMetricsDefault] forBarMetrics:UIBarMetricsDefault];
[toBar setShadowImage:fromBar.shadowImage];

toBar.translucent = fromBar.translucent;

toBar.tintColor = fromBar.tintColor;
toBar.titleTextAttributes = fromBar.titleTextAttributes;

// layer
toBar.layer.shadowColor = fromBar.layer.shadowColor;
toBar.layer.shadowOffset = fromBar.layer.shadowOffset;
toBar.layer.shadowOpacity = fromBar.layer.shadowOpacity;
toBar.layer.shadowPath = fromBar.layer.shadowPath;
toBar.layer.shadowRadius = fromBar.layer.shadowRadius;
}

- (void)km_viewDidAppear:(BOOL)animated {
[self km_restoreScrollViewContentInsetAdjustmentBehaviorIfNeeded];
UIViewController *transitionViewController = self.navigationController.km_transitionContextToViewController;
if (self.km_transitionNavigationBar) {
self.navigationController.navigationBar.barTintColor = self.km_transitionNavigationBar.barTintColor;
[self.navigationController.navigationBar setBackgroundImage:[self.km_transitionNavigationBar backgroundImageForBarMetrics:UIBarMetricsDefault] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:self.km_transitionNavigationBar.shadowImage];
[self km_settingNavigationBarMoreProperty:self.km_transitionNavigationBar];
if (!transitionViewController || [transitionViewController isEqual:self]) {
[self.km_transitionNavigationBar removeFromSuperview];
self.km_transitionNavigationBar = nil;
self.km_transitionNavigationBar = nil;
}
}
if ([transitionViewController isEqual:self]) {
Expand Down Expand Up @@ -128,13 +150,10 @@ - (void)km_addTransitionNavigationBarIfNeeded {
[self km_adjustScrollViewContentOffsetIfNeeded];
UINavigationBar *bar = [[UINavigationBar alloc] init];
bar.km_isFakeBar = YES;
bar.barStyle = self.navigationController.navigationBar.barStyle;
if (bar.translucent != self.navigationController.navigationBar.translucent) {
bar.translucent = self.navigationController.navigationBar.translucent;
}
bar.barTintColor = self.navigationController.navigationBar.barTintColor;
[bar setBackgroundImage:[self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault] forBarMetrics:UIBarMetricsDefault];
bar.shadowImage = self.navigationController.navigationBar.shadowImage;

//setting navigatonbar
[self km_settingNavigationBarFrom:self.navigationController.navigationBar toBar:bar];

[self.km_transitionNavigationBar removeFromSuperview];
self.km_transitionNavigationBar = bar;
[self km_resizeTransitionNavigationBarFrame];
Expand Down