Skip to content

Commit

Permalink
Implemented center view opacity. Only works with one side controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
Inferis committed Apr 25, 2013
1 parent 0960a04 commit 86fef1e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions ViewDeck/IIViewDeckController.h
Expand Up @@ -161,6 +161,7 @@ typedef void (^IIViewDeckControllerBounceBlock) (IIViewDeckController *controlle
@property (nonatomic, assign, readonly) CGFloat bottomViewSize;
@property (nonatomic, assign, readonly) CGFloat bottomLedgeSize;
@property (nonatomic, assign) CGFloat maxSize;
@property (nonatomic, assign) CGFloat centerViewOpacity;
@property (nonatomic, assign) BOOL resizesCenterView;
@property (nonatomic, assign) IIViewDeckPanningMode panningMode;
@property (nonatomic, assign) BOOL panningCancelsTouchesInView;
Expand Down
53 changes: 47 additions & 6 deletions ViewDeck/IIViewDeckController.m
Expand Up @@ -270,6 +270,7 @@ @implementation IIViewDeckController
@synthesize centerhiddenInteractivity = _centerhiddenInteractivity;
@synthesize centerTapper = _centerTapper;
@synthesize centerView = _centerView;
@synthesize centerViewOpacity = _centerViewOpacity;
@synthesize sizeMode = _sizeMode;
@synthesize enabled = _enabled;
@synthesize elastic = _elastic;
Expand Down Expand Up @@ -298,6 +299,7 @@ - (void)commonInitWithCenterViewController:(UIViewController *)centerController
_viewFirstAppeared = NO;
_resizesCenterView = NO;
_automaticallyUpdateTabBarItems = NO;
_centerViewOpacity = 1;
self.panners = [NSMutableArray array];
self.enabled = YES;
_offset = 0;
Expand Down Expand Up @@ -575,10 +577,10 @@ -(void)setSlidingFrameForOffset:(CGFloat)offset limit:(BOOL)limit panning:(BOOL)
}

- (void)hideAppropriateSideViews {
self.leftController.view.hidden = CGRectGetMinX(self.slidingControllerView.frame) <= 0;
self.rightController.view.hidden = CGRectGetMaxX(self.slidingControllerView.frame) >= self.referenceBounds.size.width;
self.topController.view.hidden = CGRectGetMinY(self.slidingControllerView.frame) <= 0;
self.bottomController.view.hidden = CGRectGetMaxY(self.slidingControllerView.frame) >= self.referenceBounds.size.height;
[self hide:(CGRectGetMinX(self.slidingControllerView.frame) <= 0) controllerViewForSide:IIViewDeckLeftSide];
[self hide:(CGRectGetMaxX(self.slidingControllerView.frame) >= self.referenceBounds.size.width) controllerViewForSide:IIViewDeckRightSide];
[self hide:(CGRectGetMinY(self.slidingControllerView.frame) <= 0) controllerViewForSide:IIViewDeckTopSide];
[self hide:(CGRectGetMaxY(self.slidingControllerView.frame) >= self.referenceBounds.size.height) controllerViewForSide:IIViewDeckBottomSide];
}

#pragma mark - ledges
Expand Down Expand Up @@ -1432,7 +1434,7 @@ - (BOOL)openSideView:(IIViewDeckSide)side animated:(BOOL)animated duration:(NSTi
[self notifyWillOpenSide:side animated:animated];
[self disableUserInteraction];
[UIView animateWithDuration:duration delay:0 options:options animations:^{
[self controllerForSide:side].view.hidden = NO;
[self hide:NO controllerViewForSide:side];
[self setSlidingFrameForOffset:[self ledgeOffsetForSide:side] forOrientation:IIViewDeckOffsetOrientationFromIIViewDeckSide(side)];
[self centerViewHidden];
} completion:^(BOOL finished) {
Expand All @@ -1456,6 +1458,13 @@ - (BOOL)openSideView:(IIViewDeckSide)side animated:(BOOL)animated duration:(NSTi
}
}

- (void)hide:(BOOL)hidden controllerViewForSide:(IIViewDeckSide)side {
if ([self sideControllerCount] > 1)
[self controllerForSide:side].view.hidden = hidden;
else
[self controllerForSide:side].view.hidden = NO;
}

- (BOOL)openSideView:(IIViewDeckSide)side bounceOffset:(CGFloat)bounceOffset targetOffset:(CGFloat)targetOffset bounced:(IIViewDeckControllerBounceBlock)bounced completion:(IIViewDeckControllerBlock)completed {
BOOL animated = YES;

Expand Down Expand Up @@ -1487,7 +1496,7 @@ - (BOOL)openSideView:(IIViewDeckSide)side bounceOffset:(CGFloat)bounceOffset tar
[self notifyWillOpenSide:side animated:animated];
[self disableUserInteraction];
[UIView animateWithDuration:[self openSlideDuration:YES]*longFactor delay:0 options:options animations:^{
[self controllerForSide:side].view.hidden = NO;
[self hide:NO controllerViewForSide:side];
[self setSlidingFrameForOffset:bounceOffset forOrientation:IIViewDeckOffsetOrientationFromIIViewDeckSide(side)];
} completion:^(BOOL finished) {
[self centerViewHidden];
Expand Down Expand Up @@ -2844,6 +2853,7 @@ - (void)setController:(UIViewController *)controller forSide:(IIViewDeckSide)sid
[controller setViewDeckController:self];
afterBlock(controller);
[controller didMoveToParentViewController:parentController];
[self applyCenterViewOpacityIfNeeded];
};

if (self.referenceView) {
Expand Down Expand Up @@ -2982,6 +2992,7 @@ - (void)setCenterController:(UIViewController *)centerController {
}

[_centerController view]; // make sure the view is loaded before calling viewWillAppear:
[self applyCenterViewOpacityIfNeeded];
afterBlock(_centerController);
[_centerController didMoveToParentViewController:self];

Expand Down Expand Up @@ -3103,6 +3114,36 @@ - (void)finishTransitionBlocks {
}
}

#pragma mark - Center Opacity

- (void)setCenterViewOpacity:(CGFloat)centerViewOpacity {
_centerViewOpacity = centerViewOpacity;

if (centerViewOpacity < 1 && [self sideControllerCount] > 1) {
NSLog(@"IIViewDeckController: warning: setting centerViewOpacity to value different than 1 with more than one side controller. Value will be ignored.");
return;
}

[self applyCenterViewOpacityIfNeeded];
}

- (void)applyCenterViewOpacityIfNeeded {
if (!self.centerController.view)
return;

if ([self sideControllerCount] > 1) {
// more than once controller => not opaque
if (self.centerController.view.alpha < 1) {
self.centerController.view.alpha = 1;
self.centerController.view.opaque = YES;
}
return;
}

self.centerController.view.alpha = _centerViewOpacity;
self.centerController.view.opaque = NO;
}

#pragma mark - Shadow

- (void)restoreShadowToSlidingView {
Expand Down

0 comments on commit 86fef1e

Please sign in to comment.