Skip to content

Commit

Permalink
- Added support for status bar overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
justindhill committed Dec 31, 2013
1 parent 53399e3 commit 61a3233
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 15 deletions.
3 changes: 3 additions & 0 deletions JASidePanels/Source/JASidePanelController.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ extern NSString * const JASidePanelControllerUnfreezingCenterPanel;
@property (nonatomic, strong, readonly) UIView *rightPanelContainer;
@property (nonatomic, strong, readonly) UIView *centerPanelContainer;

// Status bar cover color for when revealing side panels
- (UIColor *)statusBarCoverColor;

- (void)_handlePan:(UIGestureRecognizer *)sender;

@end
62 changes: 47 additions & 15 deletions JASidePanels/Source/JASidePanelController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ @interface JASidePanelController() {
CGRect _centerPanelRestingFrame;
CGPoint _locationBeforePan;
UIView *_centerPanelScreenshot;
UIView *_statusBarCover;
}

@property (nonatomic, readwrite) JASidePanelState state;
Expand Down Expand Up @@ -184,6 +185,16 @@ - (void)viewDidLoad {

[self _swapCenter:nil previousState:0 with:_centerPanel];
[self.view bringSubviewToFront:self.centerPanelContainer];

if (IS_IOS7())
{
CGRect statusBarFrame = CGRectMake(0., 0., self.view.width, 20.);

_statusBarCover = [[UIView alloc] initWithFrame:statusBarFrame];
_statusBarCover.backgroundColor = [self statusBarCoverColor];
_statusBarCover.alpha = 0.;
[self.view addSubview:_statusBarCover];
}
}

- (void)viewWillAppear:(BOOL)animated {
Expand Down Expand Up @@ -398,6 +409,7 @@ - (void)_swapCenter:(UIViewController *)previous previousState:(JASidePanelState
[self _loadCenterPanelWithPreviousState:previousState];
[self addChildViewController:next];
[self.centerPanelContainer insertSubview:next.view atIndex:0];

[next didMoveToParentViewController:self];
}
}
Expand Down Expand Up @@ -442,13 +454,17 @@ - (void)_freezeCenterPanel
{
if (IS_IOS7())
{
[[NSNotificationCenter defaultCenter] postNotificationName:JASidePanelControllerFreezingCenterPanel object:nil];
// [[NSNotificationCenter defaultCenter] postNotificationName:JASidePanelControllerFreezingCenterPanel object:nil];

_centerPanelScreenshot = [[UIView alloc] initWithFrame:CGRectMake(0., 0., self.view.width, 20.)];
_centerPanelScreenshot.clipsToBounds = YES;
[_centerPanelScreenshot addSubview:[[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO]];

[self.centerPanelContainer addSubview:_centerPanelScreenshot];
UIView *firstSubview = self.centerPanelContainer.subviews[0];
if ([NSStringFromClass(firstSubview.class) isEqualToString:@"UILayoutContainerView"])
firstSubview.y = 20.;

[self setNeedsStatusBarAppearanceUpdate];
}
}
Expand All @@ -457,17 +473,23 @@ - (void)_unfreezeCenterPanel
{
if (IS_IOS7())
{
[[NSNotificationCenter defaultCenter] postNotificationName:JASidePanelControllerUnfreezingCenterPanel object:nil];

// nil out centerPanelScreenshot for prefersStatusBarHidden
UIView *screenShot = _centerPanelScreenshot;
[_centerPanelScreenshot removeFromSuperview];
_centerPanelScreenshot = nil;

// show it
[self setNeedsStatusBarAppearanceUpdate];

// Remove the screenshot
[screenShot removeFromSuperview];
UIView *main = _centerPanelContainer.subviews[0];
main.y = 0;
if ([[main.viewController class] isSubclassOfClass:[UINavigationController class]])
{
UINavigationController *nav = (UINavigationController *)main.viewController;
[nav setNavigationBarHidden:YES];
[nav setNavigationBarHidden:NO];
}

[[NSNotificationCenter defaultCenter] postNotificationName:JASidePanelControllerUnfreezingCenterPanel object:nil];
}
}

Expand All @@ -479,6 +501,11 @@ - (BOOL)prefersStatusBarHidden {
}
}

- (UIColor *)statusBarCoverColor
{
return [UIColor blackColor];
}

#pragma mark - Panel Buttons

- (void)_placeButtonForLeftPanel {
Expand Down Expand Up @@ -563,14 +590,19 @@ - (void)_handlePan:(UIGestureRecognizer *)sender {
}

if (sender.state == UIGestureRecognizerStateBegan) {
[self _freezeCenterPanel];
// Make sure the status bar cover is the right color
_statusBarCover.backgroundColor = [self statusBarCoverColor];
}
}

// adjust side panel locations, if needed
if (self.style == JASidePanelMultipleActive || self.pushesSidePanels) {
[self _layoutSideContainers:NO duration:0];
}

CGFloat total = self.view.width * [self leftGapPercentage];
_statusBarCover.alpha = self.centerPanelContainer.x / total;
NSLog(@"%f / %f = %f", self.centerPanelContainer.x, total, _statusBarCover.alpha);

if (sender.state == UIGestureRecognizerStateEnded) {
CGFloat deltaX = frame.origin.x - _locationBeforePan.x;
Expand Down Expand Up @@ -794,6 +826,7 @@ - (void)_animateCenterPanel:(BOOL)shouldBounce completion:(void (^)(BOOL finishe

CGFloat duration = [self _calculatedDuration];
[UIView animateWithDuration:duration delay:0.0f options:UIViewAnimationOptionCurveLinear|UIViewAnimationOptionLayoutSubviews animations:^{
_statusBarCover.alpha = _centerPanelRestingFrame.origin.x == 0 ? 0. : 1.;
self.centerPanelContainer.frame = _centerPanelRestingFrame;
[self styleContainer:self.centerPanelContainer animate:YES duration:duration];
if (self.style == JASidePanelMultipleActive || self.pushesSidePanels) {
Expand Down Expand Up @@ -879,9 +912,9 @@ - (void)_showLeftPanel:(BOOL)animated bounce:(BOOL)shouldBounce {
self.state = JASidePanelLeftVisible;
[self _loadLeftPanel];

if (!(_centerPanelScreenshot)) {
[self _freezeCenterPanel];
}
// if (!(_centerPanelScreenshot)) {
// [self _freezeCenterPanel];
// }

[self _adjustCenterFrame];

Expand All @@ -905,9 +938,9 @@ - (void)_showRightPanel:(BOOL)animated bounce:(BOOL)shouldBounce {
self.state = JASidePanelRightVisible;
[self _loadRightPanel];

if (!(_centerPanelScreenshot)) {
[self _freezeCenterPanel];
}
// if (!(_centerPanelScreenshot)) {
// [self _freezeCenterPanel];
// }

[self _adjustCenterFrame];

Expand Down Expand Up @@ -937,15 +970,14 @@ - (void)_showCenterPanel:(BOOL)animated bounce:(BOOL)shouldBounce {
self.leftPanelContainer.hidden = YES;
self.rightPanelContainer.hidden = YES;
[self _unloadPanels];
[self _unfreezeCenterPanel];
}];
} else {
self.centerPanelContainer.frame = _centerPanelRestingFrame;
[self styleContainer:self.centerPanelContainer animate:NO duration:0.0f];
if (self.style == JASidePanelMultipleActive || self.pushesSidePanels) {
[self _layoutSideContainers:NO duration:0.0f];
}
[self _unfreezeCenterPanel];
// [self _unfreezeCenterPanel];
self.leftPanelContainer.hidden = YES;
self.rightPanelContainer.hidden = YES;
[self _unloadPanels];
Expand Down

0 comments on commit 61a3233

Please sign in to comment.