Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
be56a9a
update demo to display section header
ltebean May 2, 2015
47a1e89
check bar height when init the overlay
ltebean May 2, 2015
8bec685
fix demo - scrollViewDidScroll will get called when view is not visible
ltebean Jul 3, 2015
0240055
not touch shadow image
ltebean Jul 3, 2015
d6b1553
fix setElementsAlpha
ltebean Aug 12, 2015
c9aa593
fix a view_controller's first load
wanghengheng Nov 19, 2015
cffe0a5
Merge pull request #18 from WangHengHeng/master
ltebean Nov 19, 2015
8c5c26c
update version
ltebean Nov 19, 2015
cda6b01
Change width in frame for overlay view
michal-czw Feb 22, 2016
685ef5d
Merge pull request #25 from Enter91/master
ltebean Feb 23, 2016
944de8c
update version
ltebean Feb 23, 2016
5db4c03
修复 NavigationBar title 在 iOS 10 系统下不显示的 BUG
zhwayne Aug 18, 2016
895d499
Merge pull request #41 from zhwayne/master
ltebean Aug 19, 2016
207f9b6
bump version
ltebean Aug 19, 2016
85a6c36
check iOS version
ltebean Aug 22, 2016
1907f14
fix overlay height
ltebean Aug 22, 2016
e29713d
Fix issue 44
zhwayne Aug 27, 2016
df6a86d
Merge pull request #45 from zhwayne/master
ltebean Aug 28, 2016
7be19f8
bump version
ltebean Aug 28, 2016
3a60069
Update UINavigationBar+Awesome.m
VianPan Sep 1, 2016
f947548
Merge pull request #46 from VianPan/patch-1
ltebean Sep 2, 2016
6899c59
bump version
ltebean Sep 2, 2016
4b89685
Revert "bump version"
ltebean Sep 2, 2016
5c20c89
fix
ltebean Sep 2, 2016
3059bf1
fix: BackButton / BackIndicatorView when lt_setElementsAlpha
Dec 8, 2016
1fa8b19
add guidepost
Dec 8, 2016
6137b3f
Merge pull request #53 from rawlinxx/master
ltebean Dec 9, 2016
ec5af91
update readme
ltebean Dec 9, 2016
2eab40c
bump version
ltebean Dec 9, 2016
8a262a9
bump version
ltebean Dec 9, 2016
eb7e02d
fix back indicator view
ltebean Dec 26, 2016
4d58cf6
bump version
ltebean Dec 26, 2016
4ea6375
Update README.md
ltebean Jul 20, 2017
2dbb42e
Update README.md
ltebean Jul 20, 2017
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
4 changes: 2 additions & 2 deletions LTNavigationBar.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

Pod::Spec.new do |s|
s.name = "LTNavigationBar"
s.version = "2.0.2"
s.version = "2.1.9"
s.summary = "UINavigationBar Category which allows you to change its appearance dynamically"
s.homepage = "https://github.com/ltebean/LTNavigationbar"
s.license = "MIT"
s.author = { "ltebean" => "yucong1118@gmail.com" }
s.source = { :git => "https://github.com/ltebean/LTNavigationbar.git", :tag => 'v2.0.2'}
s.source = { :git => "https://github.com/ltebean/LTNavigationbar.git", :tag => 'v2.1.9'}
s.source_files = "LTNavigationbar/UINavigationBar+Awesome.{h,m}"
s.requires_arc = true
s.platform = :ios, '7.0'
Expand Down
2 changes: 2 additions & 0 deletions LTNavigationBar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = LTNavigationBar/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -385,6 +386,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = LTNavigationBar/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
17 changes: 10 additions & 7 deletions LTNavigationBar/BGColorDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ @implementation BGColorDemoViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
[self.navigationController.navigationBar lt_setBackgroundColor:[UIColor clearColor]];
Expand All @@ -32,8 +30,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
UIColor * color = [UIColor colorWithRed:0/255.0 green:175/255.0 blue:240/255.0 alpha:1];
CGFloat offsetY = scrollView.contentOffset.y;
if (offsetY > NAVBAR_CHANGE_POINT) {
CGFloat alpha = 1 - ((NAVBAR_CHANGE_POINT + 64 - offsetY) / 64);

CGFloat alpha = MIN(1, 1 - ((NAVBAR_CHANGE_POINT + 64 - offsetY) / 64));
[self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:alpha]];
} else {
[self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:0]];
Expand All @@ -43,27 +40,33 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
self.tableView.delegate = self;
[self scrollViewDidScroll:self.tableView];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];

}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.tableView.delegate = nil;
[self.navigationController.navigationBar lt_reset];
}

#pragma mark UITableViewDatasource

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"header";
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
return 5;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Expand Down
28 changes: 20 additions & 8 deletions LTNavigationBar/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,34 @@
<!--Title-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<viewController automaticallyAdjustsScrollViewInsets="NO" id="vXZ-lx-hvc" customClass="BGColorDemoViewController" sceneMemberID="viewController">
<viewController id="vXZ-lx-hvc" customClass="BGColorDemoViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<rect key="frame" x="0.0" y="64" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" misplaced="YES" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="ol6-pv-3ev">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="ol6-pv-3ev">
<rect key="frame" x="0.0" y="0.0" width="320" height="519"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<imageView key="tableHeaderView" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="bg.jpg" id="982-4M-Fxk">
<rect key="frame" x="0.0" y="0.0" width="320" height="223"/>
<view key="tableHeaderView" contentMode="scaleToFill" id="CA6-Ac-93j">
<rect key="frame" x="0.0" y="64" width="320" height="190"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="bg.jpg" translatesAutoresizingMaskIntoConstraints="NO" id="982-4M-Fxk">
<rect key="frame" x="0.0" y="-64" width="320" height="254"/>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="982-4M-Fxk" firstAttribute="leading" secondItem="CA6-Ac-93j" secondAttribute="leading" id="K4V-ol-kWT"/>
<constraint firstAttribute="trailing" secondItem="982-4M-Fxk" secondAttribute="trailing" id="Qaz-mA-OQA"/>
<constraint firstItem="982-4M-Fxk" firstAttribute="top" secondItem="CA6-Ac-93j" secondAttribute="top" constant="-64" id="dBf-UH-eDS"/>
<constraint firstAttribute="bottom" secondItem="982-4M-Fxk" secondAttribute="bottom" id="nTQ-eO-PdO"/>
</constraints>
</view>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" textLabel="T8Y-og-A43" style="IBUITableViewCellStyleDefault" id="bN5-oq-e1N">
<autoresizingMask key="autoresizingMask"/>
Expand All @@ -45,8 +57,8 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="ol6-pv-3ev" secondAttribute="trailing" constant="-16" id="3SJ-yy-OpP"/>
<constraint firstItem="ol6-pv-3ev" firstAttribute="top" secondItem="kh9-bI-dsS" secondAttribute="top" id="5EZ-ni-Hkp"/>
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="ol6-pv-3ev" secondAttribute="bottom" id="Ok8-Xm-KfZ"/>
<constraint firstItem="ol6-pv-3ev" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="-64" id="tpl-A3-1L6"/>
<constraint firstItem="ol6-pv-3ev" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="-16" id="zrI-Fs-jIg"/>
</constraints>
</view>
Expand Down
6 changes: 2 additions & 4 deletions LTNavigationBar/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@
<array>
<string>armv7</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion LTNavigationBar/ScrollingNavbarDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
- (void)setNavigationBarTransformProgress:(CGFloat)progress
{
[self.navigationController.navigationBar lt_setTranslationY:(-44 * progress)];
[self.navigationController.navigationBar lt_setContentAlpha:(1-progress)];
[self.navigationController.navigationBar lt_setElementsAlpha:(1-progress)];
}

- (void)viewWillAppear:(BOOL)animated
Expand Down
2 changes: 1 addition & 1 deletion LTNavigationBar/UINavigationBar+Awesome.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@interface UINavigationBar (Awesome)
- (void)lt_setBackgroundColor:(UIColor *)backgroundColor;
- (void)lt_setContentAlpha:(CGFloat)alpha;
- (void)lt_setElementsAlpha:(CGFloat)alpha;
- (void)lt_setTranslationY:(CGFloat)translationY;
- (void)lt_reset;
@end
59 changes: 23 additions & 36 deletions LTNavigationBar/UINavigationBar+Awesome.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
#import "UINavigationBar+Awesome.h"
#import <objc/runtime.h>

#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

@implementation UINavigationBar (Awesome)
static char overlayKey;
static char emptyImageKey;

- (UIView *)overlay
{
Expand All @@ -23,24 +24,14 @@ - (void)setOverlay:(UIView *)overlay
objc_setAssociatedObject(self, &overlayKey, overlay, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (UIImage *)emptyImage
{
return objc_getAssociatedObject(self, &emptyImageKey);
}

- (void)setEmptyImage:(UIImage *)image
{
objc_setAssociatedObject(self, &emptyImageKey, image, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)lt_setBackgroundColor:(UIColor *)backgroundColor
{
if (!self.overlay) {
[self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, -20, [UIScreen mainScreen].bounds.size.width, 64)];
self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) + 20)];
self.overlay.userInteractionEnabled = NO;
self.overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self insertSubview:self.overlay atIndex:0];
self.overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth; // Should not set `UIViewAutoresizingFlexibleHeight`
[[self.subviews firstObject] insertSubview:self.overlay atIndex:0];
}
self.overlay.backgroundColor = backgroundColor;
}
Expand All @@ -50,36 +41,32 @@ - (void)lt_setTranslationY:(CGFloat)translationY
self.transform = CGAffineTransformMakeTranslation(0, translationY);
}

- (void)lt_setContentAlpha:(CGFloat)alpha
- (void)lt_setElementsAlpha:(CGFloat)alpha
{
if (!self.overlay) {
[self lt_setBackgroundColor:self.barTintColor];
}
[self setAlpha:alpha forSubviewsOfView:self];
if (alpha == 1) {
if (!self.emptyImage) {
self.emptyImage = [UIImage new];
[[self valueForKey:@"_leftViews"] enumerateObjectsUsingBlock:^(UIView *view, NSUInteger i, BOOL *stop) {
view.alpha = alpha;
}];

[[self valueForKey:@"_rightViews"] enumerateObjectsUsingBlock:^(UIView *view, NSUInteger i, BOOL *stop) {
view.alpha = alpha;
}];

UIView *titleView = [self valueForKey:@"_titleView"];
titleView.alpha = alpha;
// when viewController first load, the titleView maybe nil
[[self subviews] enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:NSClassFromString(@"UINavigationItemView")]) {
obj.alpha = alpha;
}
self.backIndicatorImage = self.emptyImage;
}
}

- (void)setAlpha:(CGFloat)alpha forSubviewsOfView:(UIView *)view
{
for (UIView *subview in view.subviews) {
if (subview == self.overlay) {
continue;
if ([obj isKindOfClass:NSClassFromString(@"_UINavigationBarBackIndicatorView")]) {
obj.alpha = alpha;
}
subview.alpha = alpha;
[self setAlpha:alpha forSubviewsOfView:subview];
}
}];
}

- (void)lt_reset
{
[self setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self setShadowImage:nil];

[self.overlay removeFromSuperview];
self.overlay = nil;
}
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
![LTNavigationbar](https://cocoapod-badges.herokuapp.com/v/LTNavigationBar/badge.png)


## Deprecated
This lib uses a hacky way to achieve the result, in the new iOS version, the structure of UINavigation is changed and this lib no longer works anymore, so please check these alternatives:

- https://github.com/andreamazz/AMScrollingNavbar
- https://github.com/DanisFabric/RainbowNavigation
- https://github.com/MoZhouqi/KMNavigationBarTransition


## swift version

[https://github.com/ltebean/LTNavigationBar/tree/swift3.0](https://github.com/ltebean/LTNavigationBar/tree/swift3.0)

## Purpose
It is hard to change the appearance of UINavigationBar dynamically, so I made this lib to make the job easy.

Expand All @@ -23,7 +36,7 @@ The category includes lots of method that helps to change UINavigationBar's appe
```objective-c
@interface UINavigationBar (Awesome)
- (void)lt_setBackgroundColor:(UIColor *)backgroundColor;
- (void)lt_setContentAlpha:(CGFloat)alpha;
- (void)lt_setElementsAlpha:(CGFloat)alpha;
- (void)lt_setTranslationY:(CGFloat)translationY;
- (void)lt_reset;
@end
Expand All @@ -43,4 +56,4 @@ And usually in `viewWillDisappear`, you should call this method to avoid any sid
}
```

See the example for details~
See the example for details~