Skip to content

Commit

Permalink
Release 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
GK authored and GK committed Jul 28, 2015
1 parent 23be4e4 commit 9d2ca51
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 55 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 4 additions & 15 deletions GKFadeNavigationController.podspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#
# Be sure to run `pod lib lint GKFadeNavigationController.podspec' to ensure this is a
# valid spec and remove all comments before submitting the spec.
#
# Any lines starting with a # are optional, but encouraged
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
s.name = "GKFadeNavigationController"
s.version = "0.3"
s.version = "0.4"
s.summary = "A Navigation Controller which supports animated hiding of the Navigation Bar"
s.description = <<-DESC
This is an example implementation of a `UINavigationController` with support of animated hiding and showing it's Navigation Bar.
Expand All @@ -30,15 +21,13 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/gklka/GKFadeNavigationController.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/gklka'

s.platform = :ios, '8.0'
s.platform = :ios, '7.0'
s.requires_arc = true

s.source_files = 'Pod/Classes/**/*'
s.source_files = 'Pod/Classes/*.h'
s.resource_bundles = {
'GKFadeNavigationController' => ['Pod/Assets/*.png']
}

# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
s.public_header_files = 'Pod/Classes/**/*.h'
end
17 changes: 8 additions & 9 deletions Pod/Classes/GKFadeNavigationController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
#import <UIKit/UIKit.h>

typedef NS_ENUM(NSUInteger, GKFadeNavigationControllerNavigationBarVisibility) {
GKFadeNavigationControllerNavigationBarVisibilityUndefined = 0,
GKFadeNavigationControllerNavigationBarVisibilitySystem = 1,
GKFadeNavigationControllerNavigationBarVisibilityHidden = 2,
GKFadeNavigationControllerNavigationBarVisibilityVisible = 3
GKFadeNavigationControllerNavigationBarVisibilityUndefined = 0, // Initial value, don't set this
GKFadeNavigationControllerNavigationBarVisibilitySystem = 1, // Use System navigation bar
GKFadeNavigationControllerNavigationBarVisibilityHidden = 2, // Use custom navigation bar and hide it
GKFadeNavigationControllerNavigationBarVisibilityVisible = 3 // Use custom navigation bar and show it
};


@protocol GKFadeNavigationControllerDelegate <NSObject>

/**
You should give back the correct enum value if the controller asks you
*/
- (GKFadeNavigationControllerNavigationBarVisibility)preferredNavigationBarVisibility;

@end
Expand All @@ -26,11 +29,7 @@ typedef NS_ENUM(NSUInteger, GKFadeNavigationControllerNavigationBarVisibility) {
@interface GKFadeNavigationController : UINavigationController

/**
You can ask GKFadeNavigationController to update it's navigation bar visibility using
this function. Then the controller will ask its topViewController (in best scenario,
a controller, which conforms to the GKFadeNavigationControllerDelegate protocol), then
shows or hides the navigation bar based on what the -preferredNavigationBarVisibility
returns in the controller.
You can ask GKFadeNavigationController to update it's navigation bar visibility using this function. Then the controller will ask its topViewController (in best scenario, a controller, which conforms to the GKFadeNavigationControllerDelegate protocol), then shows or hides the navigation bar based on what the -preferredNavigationBarVisibility returns in the controller.
@param animated Play animation or make the changes instantly
*/
Expand Down
117 changes: 86 additions & 31 deletions Pod/Classes/GKFadeNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
#import "GKFadeNavigationController.h"

#define kGKDefaultVisibility YES
#define IS_OS_OLDER_THAN_IOS_8 [[[UIDevice currentDevice] systemVersion] floatValue] <= 8.f

@interface GKFadeNavigationController ()

@property (nonatomic, strong) UIVisualEffectView *visualEffectView;
@property (nonatomic, strong) UIView *fakeNavigationBarBackground;

@property (nonatomic) GKFadeNavigationControllerNavigationBarVisibility navigationBarVisibility;
@property (nonatomic, strong) UIColor *originalTintColor;

Expand All @@ -21,7 +24,7 @@ @interface GKFadeNavigationController ()

@implementation GKFadeNavigationController

#pragma mark Lifecycle
#pragma mark - Lifecycle

- (void)viewDidLoad {
[super viewDidLoad];
Expand All @@ -33,7 +36,7 @@ - (void)viewDidLoad {
[self setNavigationBarVisibilityForController:self.topViewController animated:NO];
}

#pragma mark Accessors
#pragma mark - Accessors

- (void)setNavigationBarVisibility:(GKFadeNavigationControllerNavigationBarVisibility)navigationBarVisibility
{
Expand All @@ -59,7 +62,52 @@ - (void)setNavigationBarVisibility:(GKFadeNavigationControllerNavigationBarVisib
[self setNeedsStatusBarAppearanceUpdate];
}

#pragma mark UI support
// For iOS 8+
- (UIView *)fakeNavigationBarBackground
{
if (!_fakeNavigationBarBackground) {
_fakeNavigationBarBackground = [[UIView alloc] initWithFrame:self.navigationBar.frame];
_fakeNavigationBarBackground.frame = CGRectMake(0, -20.f, self.view.frame.size.width, 64.f);
_fakeNavigationBarBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_fakeNavigationBarBackground.userInteractionEnabled = NO;
_fakeNavigationBarBackground.backgroundColor = [UIColor colorWithWhite:1.f alpha:0.9f];

// Shadow line
UIView *shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 63.5f, self.view.frame.size.width, 0.5f)];
shadowView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2f];
shadowView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

[_fakeNavigationBarBackground addSubview:shadowView];
}

return _fakeNavigationBarBackground;
}

// For iOS 7
- (UIVisualEffectView *)visualEffectView
{
if (!_visualEffectView) {
// Create a the fake navigation bar background
UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];

_visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
_visualEffectView.frame = CGRectMake(0, -20.f, self.view.frame.size.width, 64.f);
_visualEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_visualEffectView.userInteractionEnabled = NO;

// Shadow line
UIView *shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 63.5f, self.view.frame.size.width, 0.5f)];
shadowView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2f];
shadowView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

[self.visualEffectView addSubview:shadowView];
}

return _visualEffectView;
}

#pragma mark - UI support

- (UIStatusBarStyle)preferredStatusBarStyle
{
Expand All @@ -70,7 +118,7 @@ - (UIStatusBarStyle)preferredStatusBarStyle
}
}

#pragma mark Navigation Controller overrides
#pragma mark - Navigation Controller overrides

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
Expand All @@ -85,7 +133,7 @@ - (UIViewController *)popViewControllerAnimated:(BOOL)animated
return viewController;
}

#pragma mark Core functions
#pragma mark - Core functions

/**
Add custom navigation bar background, and set the colors for a hideable navigation bar
Expand All @@ -96,34 +144,31 @@ - (void)transitionFromSystemNavigationBarToCustom
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationBar.translucent = YES;
self.navigationBar.shadowImage = [UIImage new];

// Create a the fake navigation bar background
UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];

self.visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
self.visualEffectView.frame = CGRectMake(0, -20.f, self.view.frame.size.width, 64.f);
self.visualEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.visualEffectView.userInteractionEnabled = NO;

// Shadow line
UIView *shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 63.5f, self.view.frame.size.width, 0.5f)];
shadowView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2f];
shadowView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.visualEffectView addSubview:shadowView];

// Add as subviews
[self.navigationBar addSubview:self.visualEffectView];
[self.navigationBar sendSubviewToBack:self.visualEffectView];

if (IS_OS_OLDER_THAN_IOS_8) {
// iOS 7
[self.navigationBar addSubview:self.fakeNavigationBarBackground];
[self.navigationBar sendSubviewToBack:self.fakeNavigationBarBackground];

} else {
// iOS 8+
[self.navigationBar addSubview:self.visualEffectView];
[self.navigationBar sendSubviewToBack:self.visualEffectView];
}
}

/**
Remove custom navigation bar background, and reset to the system default
*/
- (void)transitionFromCustomNavigationBarToSystem
{
[self.visualEffectView removeFromSuperview];
self.visualEffectView = nil;
if (IS_OS_OLDER_THAN_IOS_8) {
// iOS 7
[self.fakeNavigationBarBackground removeFromSuperview];
} else {
// iOS 8+
[self.visualEffectView removeFromSuperview];
}

// Revert to original values
[self.navigationBar setBackgroundImage:[[UINavigationBar appearance] backgroundImageForBarMetrics:UIBarMetricsDefault] forBarMetrics:UIBarMetricsDefault];
Expand All @@ -134,9 +179,7 @@ - (void)transitionFromCustomNavigationBarToSystem
}

/**
Determines if the given view controller conforms to GKFadeNavigationControllerDelegate or not. If conforms,
asks it about the desired navigation bar visibility (visible or hidden). If it does not conform, then
falls back to system navigation controller.
Determines if the given view controller conforms to GKFadeNavigationControllerDelegate or not. If conforms, asks it about the desired navigation bar visibility (visible or hidden). If it does not conform, then falls back to system navigation controller.
@param viewController The view controller which will be presented
@param animated Present using animation or instantly
Expand Down Expand Up @@ -165,11 +208,23 @@ - (void)showCustomNavigaitonBar:(BOOL)show withFadeAnimation:(BOOL)animated
{
[UIView animateWithDuration:(animated ? 0.2 : 0) animations:^{
if (show) {
self.visualEffectView.alpha = 1;
if (IS_OS_OLDER_THAN_IOS_8) {
// iOS 7
self.fakeNavigationBarBackground.alpha = 1;
} else {
// iOS 8+
self.visualEffectView.alpha = 1;
}
self.navigationBar.tintColor = [self originalTintColor];
self.navigationBar.titleTextAttributes = [[UINavigationBar appearance] titleTextAttributes];
} else {
self.visualEffectView.alpha = 0;
if (IS_OS_OLDER_THAN_IOS_8) {
// iOS 7
self.fakeNavigationBarBackground.alpha = 0;
} else {
// iOS 8+
self.visualEffectView.alpha = 0;
}
self.navigationBar.tintColor = [UIColor whiteColor];
self.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor clearColor]};
}
Expand Down

0 comments on commit 9d2ca51

Please sign in to comment.