Skip to content

Commit

Permalink
兼容 iOS 15
Browse files Browse the repository at this point in the history
fix #148, #149, #150
  • Loading branch information
listenzz committed Oct 8, 2021
1 parent 7e0095d commit dcdc526
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions HBDNavigationBar/Classes/HBDNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,17 @@ - (void)showViewController:(UIViewController * _Nonnull)viewController withCoord
[self.nav showFakeBarFrom:from to:to];
} else {
[self.nav updateNavigationBarForViewController:viewController];
if (@available(iOS 15.0, *)) {
self.nav.navigationBar.scrollEdgeAppearance.backgroundColor = viewController.hbd_barTintColor;
self.nav.navigationBar.standardAppearance.backgroundColor = viewController.hbd_barTintColor;
}
}
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
self.nav.poppingViewController = nil;
if (@available(iOS 15.0, *)) {
self.nav.navigationBar.scrollEdgeAppearance.backgroundColor = UIColor.clearColor;
self.nav.navigationBar.standardAppearance.backgroundColor = UIColor.clearColor;
}

if (context.isCancelled) {
if (to == viewController) {
Expand Down Expand Up @@ -384,11 +392,28 @@ - (UIViewController *)childViewControllerForStatusBarHidden {
return self.topViewController;
}

- (UIViewController *)childViewControllerForStatusBarStyle {
return self.topViewController;
}

- (UIViewController *)childViewControllerForHomeIndicatorAutoHidden {
return self.topViewController;
}

- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationBar setTranslucent:YES];
[self.navigationBar setShadowImage:[UINavigationBar appearance].shadowImage];

if (@available(iOS 15.0, *)) {
UINavigationBarAppearance *scrollEdgeAppearance = [[UINavigationBarAppearance alloc] init];
[scrollEdgeAppearance configureWithTransparentBackground];
scrollEdgeAppearance.shadowColor = UIColor.clearColor;
scrollEdgeAppearance.backgroundColor = UIColor.clearColor;
self.navigationBar.scrollEdgeAppearance = scrollEdgeAppearance;
self.navigationBar.standardAppearance = [scrollEdgeAppearance copy];
}

self.navigationDelegate = [[HBDNavigationControllerDelegate alloc] initWithNavigationController:self];
self.navigationDelegate.proxiedDelegate = self.delegate;
self.delegate = self.navigationDelegate;
Expand Down Expand Up @@ -487,6 +512,10 @@ - (void)updateNavigationBarStyleForViewController:(UIViewController *)vc {
- (void)updateNavigationBarTinitColorForViewController:(UIViewController *)vc {
self.navigationBar.tintColor = vc.hbd_tintColor;
self.navigationBar.titleTextAttributes = vc.hbd_titleTextAttributes;
if (@available(iOS 15.0, *)) {
self.navigationBar.scrollEdgeAppearance.titleTextAttributes = vc.hbd_titleTextAttributes;
self.navigationBar.standardAppearance.titleTextAttributes = vc.hbd_titleTextAttributes;
}
}

- (void)updateNavigationBarAlphaForViewController:(UIViewController *)vc {
Expand Down

0 comments on commit dcdc526

Please sign in to comment.