From 93772f7a652a6d0ea2c45c55ebe442a71f761c21 Mon Sep 17 00:00:00 2001 From: Ilya Velilyaev Date: Thu, 3 Nov 2016 13:40:41 +0300 Subject: [PATCH 1/4] added background color to navigation bar progress view --- ...INavigationController+M13ProgressViewBar.h | 6 ++ ...INavigationController+M13ProgressViewBar.m | 57 +++++++++++++++++-- ...iewBarNavigationControllerViewController.m | 1 + 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/Classes/NavigationController/UINavigationController+M13ProgressViewBar.h b/Classes/NavigationController/UINavigationController+M13ProgressViewBar.h index 8fdfe45..feaf529 100644 --- a/Classes/NavigationController/UINavigationController+M13ProgressViewBar.h +++ b/Classes/NavigationController/UINavigationController+M13ProgressViewBar.h @@ -50,5 +50,11 @@ @param secondaryColor The color to set. */ - (void)setSecondaryColor:(UIColor *)secondaryColor; +/** + The background color of the progress bar, if nil, the background color will be the clearColor. + + @param background The color to set. + */ +- (void)setBackgroundColor:(UIColor *)backgroundColor; @end diff --git a/Classes/NavigationController/UINavigationController+M13ProgressViewBar.m b/Classes/NavigationController/UINavigationController+M13ProgressViewBar.m index cf02913..6355d95 100644 --- a/Classes/NavigationController/UINavigationController+M13ProgressViewBar.m +++ b/Classes/NavigationController/UINavigationController+M13ProgressViewBar.m @@ -20,6 +20,8 @@ static char isShowingProgressKey; static char primaryColorKey; static char secondaryColorKey; +static char backgroundColorKey; +static char backgroundViewKey; @implementation UINavigationController (M13ProgressViewBar) @@ -91,8 +93,8 @@ - (void)animateProgress:(CADisplayLink *)displayLink - (void)finishProgress { UIView *progressView = [self getProgressView]; - - if (progressView) { + UIView *backgroundView = [self getBackgroundView]; + if (progressView && backgroundView) { dispatch_async(dispatch_get_main_queue(), ^{ [UIView animateWithDuration:0.1 animations:^{ CGRect progressFrame = progressView.frame; @@ -101,8 +103,11 @@ - (void)finishProgress } completion:^(BOOL finished) { [UIView animateWithDuration:0.5 animations:^{ progressView.alpha = 0; + backgroundView.alpha = 0; } completion:^(BOOL finished) { [progressView removeFromSuperview]; + [backgroundView removeFromSuperview]; + backgroundView.alpha = 1; progressView.alpha = 1; [self setTitle:nil]; [self setIsShowingProgressBar:NO]; @@ -115,14 +120,18 @@ - (void)finishProgress - (void)cancelProgress { UIView *progressView = [self getProgressView]; - - if (progressView) { + UIView *backgroundView = [self getBackgroundView]; + + if (progressView && backgroundView) { dispatch_async(dispatch_get_main_queue(), ^{ [UIView animateWithDuration:0.5 animations:^{ progressView.alpha = 0; + backgroundView.alpha = 0; } completion:^(BOOL finished) { [progressView removeFromSuperview]; + [backgroundView removeFromSuperview]; progressView.alpha = 1; + backgroundView.alpha = 1; [self setTitle:nil]; [self setIsShowingProgressBar:NO]; }]; @@ -154,9 +163,11 @@ - (UIInterfaceOrientation)currentDeviceOrientation - (void)showProgress { UIView *progressView = [self getProgressView]; + UIView *backgroundView = [self getBackgroundView]; [UIView animateWithDuration:.1 animations:^{ progressView.alpha = 1; + backgroundView.alpha = 1; }]; [self setIsShowingProgressBar:YES]; @@ -182,6 +193,19 @@ - (void)updateProgressWithInterfaceOrientation:(UIInterfaceOrientation)interface [self setProgressView:progressView]; } + //Create background view if it doesn't exist + UIView *backgroundView = [self getBackgroundView]; + if (!backgroundView) + { + backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 2.5)]; + backgroundView.backgroundColor = [UIColor clearColor]; + if ([self getBackgroundColor]) { + backgroundView.backgroundColor = [self getBackgroundColor]; + } + backgroundView.clipsToBounds = YES; + [self setBackgroundView:backgroundView]; + } + //Calculate the frame of the navigation bar, based off the orientation. UIView *topView = self.topViewController.view; CGSize screenSize; @@ -209,6 +233,7 @@ - (void)updateProgressWithInterfaceOrientation:(UIInterfaceOrientation)interface //Check if the progress view is in its superview and if we are showing the bar. if (progressView.superview == nil && [self isShowingProgressBar]) { + [self.navigationBar addSubview:backgroundView]; [self.navigationBar addSubview:progressView]; } @@ -222,7 +247,7 @@ - (void)updateProgressWithInterfaceOrientation:(UIInterfaceOrientation)interface //Calculate the width of the progress view progressView.frame = CGRectMake(0, height - 2.5, width, 2.5); } - + backgroundView.frame = CGRectMake(0, height - 2.5, width, 2.5); } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration @@ -437,6 +462,17 @@ - (UIView *)getProgressView return objc_getAssociatedObject(self, &progressViewKey); } +- (void)setBackgroundView:(UIView *)view +{ + objc_setAssociatedObject(self, &backgroundViewKey, view, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (UIView *)getBackgroundView +{ + return objc_getAssociatedObject(self, &backgroundViewKey); +} + + - (void)setIndeterminate:(BOOL)indeterminate { objc_setAssociatedObject(self, &indeterminateKey, [NSNumber numberWithBool:indeterminate], OBJC_ASSOCIATION_RETAIN_NONATOMIC); @@ -488,4 +524,15 @@ - (UIColor *)getSecondaryColor return objc_getAssociatedObject(self, &secondaryColorKey); } +- (void)setBackgroundColor:(UIColor *)backgroundColor +{ + objc_setAssociatedObject(self, &backgroundColorKey, backgroundColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + [self setIndeterminate:[self getIndeterminate]]; +} + +- (UIColor *)getBackgroundColor +{ + return objc_getAssociatedObject(self, &backgroundColorKey); +} + @end diff --git a/M13ProgressSuite/M13ProgressViewBarNavigationControllerViewController.m b/M13ProgressSuite/M13ProgressViewBarNavigationControllerViewController.m index f375af7..26df93b 100644 --- a/M13ProgressSuite/M13ProgressViewBarNavigationControllerViewController.m +++ b/M13ProgressSuite/M13ProgressViewBarNavigationControllerViewController.m @@ -33,6 +33,7 @@ - (void)viewDidLoad { [self.navigationController showProgress]; [super viewDidLoad]; + [self.navigationController setBackgroundColor:[UIColor blackColor]]; // Do any additional setup after loading the view. } From 8971d7493a3f747d12b8adb2da2210c1ec7790ad Mon Sep 17 00:00:00 2001 From: Ilya Velilyaev Date: Thu, 3 Nov 2016 13:48:52 +0300 Subject: [PATCH 2/4] fixed background color not setting --- .../UINavigationController+M13ProgressViewBar.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Classes/NavigationController/UINavigationController+M13ProgressViewBar.m b/Classes/NavigationController/UINavigationController+M13ProgressViewBar.m index 6355d95..1754c83 100644 --- a/Classes/NavigationController/UINavigationController+M13ProgressViewBar.m +++ b/Classes/NavigationController/UINavigationController+M13ProgressViewBar.m @@ -186,12 +186,12 @@ - (void)updateProgressWithInterfaceOrientation:(UIInterfaceOrientation)interface { progressView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 2.5)]; progressView.backgroundColor = self.navigationBar.tintColor; - if ([self getPrimaryColor]) { - progressView.backgroundColor = [self getPrimaryColor]; - } progressView.clipsToBounds = YES; [self setProgressView:progressView]; } + if ([self getPrimaryColor]) { + progressView.backgroundColor = [self getPrimaryColor]; + } //Create background view if it doesn't exist UIView *backgroundView = [self getBackgroundView]; @@ -199,12 +199,12 @@ - (void)updateProgressWithInterfaceOrientation:(UIInterfaceOrientation)interface { backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 2.5)]; backgroundView.backgroundColor = [UIColor clearColor]; - if ([self getBackgroundColor]) { - backgroundView.backgroundColor = [self getBackgroundColor]; - } backgroundView.clipsToBounds = YES; [self setBackgroundView:backgroundView]; } + if ([self getBackgroundColor]) { + backgroundView.backgroundColor = [self getBackgroundColor]; + } //Calculate the frame of the navigation bar, based off the orientation. UIView *topView = self.topViewController.view; From 8d97ac8b7135db20e6fc957757c50dc8bd713914 Mon Sep 17 00:00:00 2001 From: Ilya Velilyaev Date: Thu, 3 Nov 2016 13:59:18 +0300 Subject: [PATCH 3/4] Added example --- .../Base.lproj/Main_iPhone.storyboard | 491 ++++++++++-------- ...iewBarNavigationControllerViewController.h | 3 + ...iewBarNavigationControllerViewController.m | 19 + 3 files changed, 304 insertions(+), 209 deletions(-) diff --git a/M13ProgressSuite/Base.lproj/Main_iPhone.storyboard b/M13ProgressSuite/Base.lproj/Main_iPhone.storyboard index d2b2da8..d71cf48 100644 --- a/M13ProgressSuite/Base.lproj/Main_iPhone.storyboard +++ b/M13ProgressSuite/Base.lproj/Main_iPhone.storyboard @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -10,21 +14,21 @@ - + - + - + - + - + - + - + - +