diff --git a/KMNavigationBarTransition/UINavigationController+KMNavigationBarTransition.m b/KMNavigationBarTransition/UINavigationController+KMNavigationBarTransition.m index 9743056..9ef6338 100755 --- a/KMNavigationBarTransition/UINavigationController+KMNavigationBarTransition.m +++ b/KMNavigationBarTransition/UINavigationController+KMNavigationBarTransition.m @@ -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; @@ -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; @@ -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; @@ -149,6 +145,15 @@ - (void)km_setViewControllers:(NSArray *)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]; } diff --git a/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition.m b/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition.m index 3638125..169c111 100644 --- a/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition.m +++ b/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition.m @@ -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]) { @@ -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];