diff --git a/LTNavigationBar.podspec b/LTNavigationBar.podspec index 77098fa..3f4d229 100644 --- a/LTNavigationBar.podspec +++ b/LTNavigationBar.podspec @@ -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' diff --git a/LTNavigationBar.xcodeproj/project.pbxproj b/LTNavigationBar.xcodeproj/project.pbxproj index 3958689..620d1a9 100644 --- a/LTNavigationBar.xcodeproj/project.pbxproj +++ b/LTNavigationBar.xcodeproj/project.pbxproj @@ -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)"; @@ -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)"; diff --git a/LTNavigationBar/BGColorDemoViewController.m b/LTNavigationBar/BGColorDemoViewController.m index 32bada3..87cca77 100644 --- a/LTNavigationBar/BGColorDemoViewController.m +++ b/LTNavigationBar/BGColorDemoViewController.m @@ -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]]; @@ -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]]; @@ -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 diff --git a/LTNavigationBar/Base.lproj/Main.storyboard b/LTNavigationBar/Base.lproj/Main.storyboard index 83a3a8e..67445e9 100644 --- a/LTNavigationBar/Base.lproj/Main.storyboard +++ b/LTNavigationBar/Base.lproj/Main.storyboard @@ -8,22 +8,34 @@ - + - + - - + + - - + + - + + + + + + + + + + + + + @@ -45,8 +57,8 @@ + - diff --git a/LTNavigationBar/Info.plist b/LTNavigationBar/Info.plist index de59cfc..c5e0609 100644 --- a/LTNavigationBar/Info.plist +++ b/LTNavigationBar/Info.plist @@ -30,13 +30,11 @@ armv7 - UIViewControllerBasedStatusBarAppearance - UISupportedInterfaceOrientations UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight + UIViewControllerBasedStatusBarAppearance + diff --git a/LTNavigationBar/ScrollingNavbarDemoViewController.m b/LTNavigationBar/ScrollingNavbarDemoViewController.m index 9fe889e..eaa8548 100644 --- a/LTNavigationBar/ScrollingNavbarDemoViewController.m +++ b/LTNavigationBar/ScrollingNavbarDemoViewController.m @@ -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 diff --git a/LTNavigationBar/UINavigationBar+Awesome.h b/LTNavigationBar/UINavigationBar+Awesome.h index c224e27..77e02fe 100644 --- a/LTNavigationBar/UINavigationBar+Awesome.h +++ b/LTNavigationBar/UINavigationBar+Awesome.h @@ -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 diff --git a/LTNavigationBar/UINavigationBar+Awesome.m b/LTNavigationBar/UINavigationBar+Awesome.m index 15e6ac9..10adb5b 100644 --- a/LTNavigationBar/UINavigationBar+Awesome.m +++ b/LTNavigationBar/UINavigationBar+Awesome.m @@ -9,9 +9,10 @@ #import "UINavigationBar+Awesome.h" #import +#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 { @@ -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; } @@ -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; } diff --git a/README.md b/README.md index 22d1aa3..dada94a 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 @@ -43,4 +56,4 @@ And usually in `viewWillDisappear`, you should call this method to avoid any sid } ``` -See the example for details~ \ No newline at end of file +See the example for details~