Skip to content
This repository was archived by the owner on Apr 23, 2026. It is now read-only.
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
208 changes: 14 additions & 194 deletions Example/HBDNavigationBar.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
LastUpgradeVersion = "1610"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
14 changes: 7 additions & 7 deletions Example/HBDNavigationBar/BViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ - (void)viewDidLoad {
self.view.backgroundColor = [UIColor colorWithRed:((float) arc4random_uniform(256) / 255.0) green:((float) arc4random_uniform(256) / 255.0) blue:((float) arc4random_uniform(256) / 255.0) alpha:1.0];
}

- (void)viewWillAppear:(BOOL)animated {
NSLog(@"%s", __FUNCTION__);
}

- (void)viewDidAppear:(BOOL)animated {
NSLog(@"%s", __FUNCTION__);
}
//- (void)viewWillAppear:(BOOL)animated {
// NSLog(@"%s", __FUNCTION__);
//}
//
//- (void)viewDidAppear:(BOOL)animated {
// NSLog(@"%s", __FUNCTION__);
//}

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"pop-to-root" object:nil];
Expand Down
21 changes: 12 additions & 9 deletions Example/HBDNavigationBar/DemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ - (void)viewDidLoad {

}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"viewWillAppear:%@", self);
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
NSLog(@"viewWillDisappear:%@", self);
}
//- (void)viewWillAppear:(BOOL)animated {
// [super viewWillAppear:animated];
// NSLog(@"viewWillAppear:%@", self);
//}
//
//- (void)viewWillDisappear:(BOOL)animated {
// [super viewWillDisappear:animated];
// NSLog(@"viewWillDisappear:%@", self);
//}

- (IBAction)sliderValueChanged:(UISlider *)sender {
self.alphaComponent.text = [NSString stringWithFormat:@"%.2f", sender.value];
Expand Down Expand Up @@ -93,6 +93,9 @@ - (IBAction)dismiss:(UIButton *)sender {
[self dismissViewControllerAnimated:YES completion:^{

}];
} else {
self.hbd_tintColor = [UIColor redColor];
[self hbd_setNeedsUpdateNavigationBar];
}
}

Expand Down
2 changes: 2 additions & 0 deletions Example/HBDNavigationBar/HBDNavigationBar-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
</dict>
</plist>
12 changes: 2 additions & 10 deletions Example/HBDNavigationBar/YPGradientDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ - (void)viewDidLoad {

tableView.delegate = self;
tableView.dataSource = self;
if (@available(iOS 11, *)) {
tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"lakeside_sunset" ofType:@"png"];
UIImage *headerImage = [UIImage imageWithContentsOfFile:imagePath];
Expand Down Expand Up @@ -132,11 +128,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat headerHeight = CGRectGetHeight(self.headerView.frame);
if (@available(iOS 11, *)) {
headerHeight -= self.view.safeAreaInsets.top;
} else {
headerHeight -= [self.topLayoutGuide length];
}
headerHeight -= self.view.safeAreaInsets.top;

CGFloat progress = scrollView.contentOffset.y + scrollView.contentInset.top;
CGFloat gradientProgress = MIN(1, MAX(0, progress / headerHeight));
Expand Down
77 changes: 48 additions & 29 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

22 changes: 0 additions & 22 deletions Example/Tests/Tests-Info.plist

This file was deleted.

7 changes: 0 additions & 7 deletions Example/Tests/Tests-Prefix.pch

This file was deleted.

35 changes: 0 additions & 35 deletions Example/Tests/Tests.m

This file was deleted.

2 changes: 0 additions & 2 deletions Example/Tests/en.lproj/InfoPlist.strings

This file was deleted.

6 changes: 3 additions & 3 deletions HBDNavigationBar.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'HBDNavigationBar'
s.version = '1.9.8'
s.version = '2.0.0'
s.summary = 'An aspiring UINavigationBar.'

# This description is used to generate tags and improve search results.
Expand All @@ -25,10 +25,10 @@ TODO: Add long description of the pod here.
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'listen' => 'listenzz@163.com' }
s.source = { :git => 'https://github.com/listenzz/HBDNavigationBar.git', :tag => s.version.to_s }
s.source = { :git => 'https://github.com/xygkevin/HBDNavigationBar.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

s.ios.deployment_target = '9.0'
s.ios.deployment_target = '13.0'

s.source_files = 'HBDNavigationBar/Classes/**/*'

Expand Down
6 changes: 6 additions & 0 deletions HBDNavigationBar/Classes/HBDNavigationBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@

#import <UIKit/UIKit.h>

@class HBDNavigationBar;
@protocol HBDNavigationBarDelegate <NSObject>
- (void)shouldUpdateNavigationBar:(HBDNavigationBar *)navigationBar;
@end

@interface HBDNavigationBar : UINavigationBar

@property(nonatomic, strong, readonly) UIImageView *shadowImageView;
@property(nonatomic, strong, readonly) UIVisualEffectView *fakeView;
@property(nonatomic, strong, readonly) UIImageView *backgroundImageView;
@property(nonatomic, strong, readonly) UILabel *backButtonLabel;
@property(nonatomic, strong, readonly) UIView *hbd_backgroundView;
@property (nonatomic, weak) id<HBDNavigationBarDelegate> mydelegate;

@end

Expand Down
9 changes: 9 additions & 0 deletions HBDNavigationBar/Classes/HBDNavigationBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
return view;
}

- (void)didAddSubview:(UIView *)subview {
[subview didAddSubview:subview];
if ([subview isKindOfClass:NSClassFromString(@"_UIBarBackground")]) {
if (self.mydelegate && [self.mydelegate respondsToSelector:@selector(shouldUpdateNavigationBar:)]) {
[self.mydelegate shouldUpdateNavigationBar:self];
}
}
}

- (void)layoutSubviews {
[super layoutSubviews];
self.fakeView.frame = self.fakeView.superview.bounds;
Expand Down
40 changes: 37 additions & 3 deletions HBDNavigationBar/Classes/HBDNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ - (instancetype)initWithNavigationController:(HBDNavigationController *)navigati

@end

@interface HBDNavigationController ()
@interface HBDNavigationController () <HBDNavigationBarDelegate>

@property(nonatomic, readonly) HBDNavigationBar *navigationBar;
@property(nonatomic, strong) UIVisualEffectView *fromFakeBar;
Expand Down Expand Up @@ -384,17 +384,22 @@ @implementation HBDNavigationController
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController {
if (self = [super initWithNavigationBarClass:[HBDNavigationBar class] toolbarClass:nil]) {
self.viewControllers = @[rootViewController];
self.navigationBar.mydelegate = self;
}
return self;
}

- (UINavigationController *)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass {
NSAssert([navigationBarClass isSubclassOfClass:[HBDNavigationBar class]], @"navigationBarClass Must be a subclass of HBDNavigationBar");
return [super initWithNavigationBarClass:navigationBarClass toolbarClass:toolbarClass];
self = [super initWithNavigationBarClass:navigationBarClass toolbarClass:toolbarClass];
self.navigationBar.mydelegate = self;
return self;
}

- (UINavigationController *)init {
return [super initWithNavigationBarClass:[HBDNavigationBar class] toolbarClass:nil];
self = [super initWithNavigationBarClass:[HBDNavigationBar class] toolbarClass:nil];
self.navigationBar.mydelegate = self;
return self;
}

- (void)setDelegate:(id <UINavigationControllerDelegate>)delegate {
Expand Down Expand Up @@ -677,5 +682,34 @@ - (CGRect)fakeShadowFrameWithBarFrame:(CGRect)frame {
return CGRectMake(frame.origin.x, frame.size.height + frame.origin.y - hairlineWidth, frame.size.width, hairlineWidth);
}

/// MARK: - HBDNavigationBarDelegate
- (void)shouldUpdateNavigationBar:(HBDNavigationBar *)navigationBar {

UIViewController *viewController = self.topViewController;

[self updateNavigationBarStyleForViewController:viewController];
[self updateNavigationBarBackgroundForViewController:viewController];

id <UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;

if (coordinator) {
UIViewController *from = [coordinator viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *to = [coordinator viewControllerForKey:UITransitionContextToViewControllerKey];

[self updateNavigationBarTintColorForViewController:from];
[self updateNavigationBarTintColorForViewController:to];

if ([self.viewControllers containsObject:from]) {
[self updateNavigationBarAlphaForViewController:from];
} else {
[self updateNavigationBarAlphaForViewController:to];
}

if (shouldShowFake(viewController, from, to)) {
[self showFakeBarFrom:from to:to];
}
}
}

@end