From 4b1cc9a13eb172345accf66a997a1120dc0b22c8 Mon Sep 17 00:00:00 2001 From: Reinier Melian Massip Date: Wed, 25 May 2016 18:26:05 -0400 Subject: [PATCH] added new implementation to show left viewController over central viewController --- .../SWRevealViewController.h | 2 +- .../SWRevealViewController.m | 310 ++++++++++++------ 2 files changed, 215 insertions(+), 97 deletions(-) diff --git a/SWRevealViewController/SWRevealViewController.h b/SWRevealViewController/SWRevealViewController.h index 345dfaa..79cd6d0 100755 --- a/SWRevealViewController/SWRevealViewController.h +++ b/SWRevealViewController/SWRevealViewController.h @@ -263,7 +263,7 @@ typedef NS_ENUM(NSInteger, SWRevealToggleAnimationType) // If YES (default is NO) the controller will allow permanent dragging up to the rightMostPosition @property (nonatomic) BOOL stableDragOnOverdraw; @property (nonatomic) BOOL stableDragOnLeftOverdraw; // <-- simetric implementation of the above for the rightViewController - +@property (assign, nonatomic) BOOL rearViewWillDisplayOverFrontView; // If YES (default is NO) the front view controller will be ofsseted vertically by the height of a navigation bar. // Use this on iOS7 when you add an instance of RevealViewController as a child of a UINavigationController (or another SWRevealViewController) // and you want the front view controller to be presented below the navigation bar of its UINavigationController grand parent. diff --git a/SWRevealViewController/SWRevealViewController.m b/SWRevealViewController/SWRevealViewController.m index d378d13..6d48723 100755 --- a/SWRevealViewController/SWRevealViewController.m +++ b/SWRevealViewController/SWRevealViewController.m @@ -1,5 +1,5 @@ /* - + Copyright (c) 2013 Joan Lluch Permission is hereby granted, free of charge, to any person obtaining a copy @@ -19,10 +19,10 @@ of this software and associated documentation files (the "Software"), to deal LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - + Early code inspired on a similar class by Philip Kluz (Philip.Kluz@zuui.org) -*/ + */ #import @@ -42,7 +42,7 @@ static CGFloat statusBarAdjustment( UIView* view ) if ( CGRectIntersectsRect(viewFrame, statusBarFrame) ) adjustment = fminf(statusBarFrame.size.width, statusBarFrame.size.height); - + return adjustment; } @@ -89,11 +89,11 @@ - (id)initWithFrame:(CGRect)frame controller:(SWRevealViewController*)controller { _c = controller; CGRect bounds = self.bounds; - + _frontView = [[UIView alloc] initWithFrame:bounds]; _frontView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; [self reloadShadow]; - + [self addSubview:_frontView]; } return self; @@ -131,6 +131,14 @@ - (void)prepareRearViewForPosition:(FrontViewPosition)newPosition _rearView = [[UIView alloc] initWithFrame:self.bounds]; _rearView.autoresizingMask = /*UIViewAutoresizingFlexibleWidth|*/UIViewAutoresizingFlexibleHeight; [self insertSubview:_rearView belowSubview:_frontView]; + + CALayer*rearViewLayer = _rearView.layer; + rearViewLayer.masksToBounds = NO; + rearViewLayer.shadowColor = [UIColor blackColor].CGColor; + //frontViewLayer.shadowOpacity = 1.0f; + rearViewLayer.shadowOpacity = _c.frontViewShadowOpacity; + rearViewLayer.shadowOffset = _c.frontViewShadowOffset; + rearViewLayer.shadowRadius = _c.frontViewShadowRadius; } CGFloat xLocation = [self frontLocationForPosition:_c.frontViewPosition]; @@ -184,7 +192,7 @@ - (CGFloat)frontLocationForPosition:(FrontViewPosition)frontViewPosition else if ( frontViewPosition > FrontViewPositionRight ) location = revealWidth + revealOverdraw; - + return location*symetry; } @@ -206,7 +214,7 @@ - (void)dragFrontViewToXLocation:(CGFloat)xLocation - (void)layoutSubviews { if ( _disableLayout ) return; - + CGRect bounds = self.bounds; FrontViewPosition position = _c.frontViewPosition; @@ -227,6 +235,9 @@ - (void)layoutSubviews UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:shadowBounds]; _frontView.layer.shadowPath = shadowPath.CGPath; + + UIBezierPath *rearShadowPath = [UIBezierPath bezierPathWithRect:_rearView.bounds]; + _rearView.layer.shadowPath = rearShadowPath.CGPath; } @@ -288,10 +299,21 @@ - (void)_layoutRearViewsForLocation:(CGFloat)xLocation CGFloat rearRevealWidth = _c.rearViewRevealWidth; if ( rearRevealWidth < 0) rearRevealWidth = bounds.size.width + _c.rearViewRevealWidth; - CGFloat rearXLocation = scaledValue(xLocation, -_c.rearViewRevealDisplacement, 0, 0, rearRevealWidth); + CGFloat rearXLocation; + if(_c.rearViewWillDisplayOverFrontView) + { + rearXLocation = scaledValue(xLocation, -_c.rearViewRevealWidth, 0, 0, rearRevealWidth); + }else + rearXLocation = scaledValue(xLocation, -_c.rearViewRevealDisplacement, 0, 0, rearRevealWidth); CGFloat rearWidth = rearRevealWidth + _c.rearViewRevealOverdraw; - _rearView.frame = CGRectMake(rearXLocation, 0.0, rearWidth, bounds.size.height); + if(_c.rearViewWillDisplayOverFrontView) + { + _rearView.frame = CGRectMake(rearXLocation-_c.rearViewRevealOverdraw, 0.0, rearWidth/*-_c.rearViewRevealOverdraw*/, bounds.size.height); + }else + { + _rearView.frame = CGRectMake(rearXLocation, 0.0, rearWidth, bounds.size.height); + } CGFloat rightRevealWidth = _c.rightViewRevealWidth; if ( rightRevealWidth < 0) rightRevealWidth = bounds.size.width + _c.rightViewRevealWidth; @@ -309,7 +331,7 @@ - (void)_prepareForNewPosition:(FrontViewPosition)newPosition; return; int symetry = newPosition)transitionC { UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; - + if ( fromViewController ) { [UIView transitionFromView:fromViewController.view toView:toViewController.view duration:_duration - options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationOptionOverrideInheritedOptions - completion:^(BOOL finished) { [transitionContext completeTransition:finished]; }]; + options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationOptionOverrideInheritedOptions + completion:^(BOOL finished) { [transitionContext completeTransition:finished]; }]; } else { @@ -530,8 +552,8 @@ - (void)animateTransition:(id )transitionC toView.alpha = 0; [UIView animateWithDuration:_duration delay:0 options:UIViewAnimationOptionCurveEaseOut - animations:^{ toView.alpha = alpha;} - completion:^(BOOL finished) { [transitionContext completeTransition:finished];}]; + animations:^{ toView.alpha = alpha;} + completion:^(BOOL finished) { [transitionContext completeTransition:finished];}]; } } @@ -554,7 +576,7 @@ @implementation SWRevealViewControllerPanGestureRecognizer - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; - + UITouch *touch = [touches anyObject]; _beginPoint = [touch locationInView:self.view]; _dragging = NO; @@ -615,7 +637,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder if ( self ) { [self _initDefaultProperties]; - } + } return self; } @@ -639,16 +661,43 @@ - (id)initWithRearViewController:(UIViewController *)rearViewController frontVie } +- (float)getRearRevealWidth +{ + if([UIScreen mainScreen].bounds.size.width == 320 && [UIScreen mainScreen].bounds.size.height == 480) + { + //is Iphone 4, 4s screen + return 260.0f; + } + + if([UIScreen mainScreen].bounds.size.width == 320 && [UIScreen mainScreen].bounds.size.height == 568) + { + //is Iphone 5, 5s, SE screen + return 260.0f; + } + + if([UIScreen mainScreen].bounds.size.width == 375 && [UIScreen mainScreen].bounds.size.height == 667) + { + //is iphone 6 , 6s screens + } + + if([UIScreen mainScreen].bounds.size.width == 414 && [UIScreen mainScreen].bounds.size.height == 736) + { + //is iphone 6plus , 6s plus screens + } + + return 1000; +} + - (void)_initDefaultProperties { _frontViewPosition = FrontViewPositionLeft; _rearViewPosition = FrontViewPositionLeft; _rightViewPosition = FrontViewPositionLeft; - _rearViewRevealWidth = 260.0f; _rearViewRevealOverdraw = 60.0f; + _rearViewRevealWidth = [UIScreen mainScreen].bounds.size.width - 60.0f; _rearViewRevealDisplacement = 40.0f; - _rightViewRevealWidth = 260.0f; _rightViewRevealOverdraw = 60.0f; + _rightViewRevealWidth = [UIScreen mainScreen].bounds.size.width - 60.0f; _rightViewRevealDisplacement = 40.0f; _bounceBackOnOverdraw = YES; _bounceBackOnLeftOverdraw = YES; @@ -669,6 +718,7 @@ - (void)_initDefaultProperties _draggableBorderWidth = 0.0f; _clipsViewsToBounds = NO; _extendsPointInsideHit = NO; + _rearViewWillDisplayOverFrontView = YES; } @@ -709,7 +759,7 @@ - (void)loadView // On iOS7 the applicationFrame does not return the whole screen. This is possibly a bug. // As a workaround we use the screen bounds, this still works on iOS6, any zero based frame would work anyway! CGRect frame = [[UIScreen mainScreen] bounds]; - + // create a custom content view for the controller _contentView = [[SWRevealView alloc] initWithFrame:frame controller:self]; @@ -718,12 +768,12 @@ - (void)loadView // set the content view to clip its bounds if requested [_contentView setClipsToBounds:_clipsViewsToBounds]; - + // set our contentView to the controllers view self.view = _contentView; // Apple also tells us to do this: - _contentView.backgroundColor = [UIColor blackColor]; + _contentView.backgroundColor = [UIColor whiteColor]; // we set the current frontViewPosition to none before seting the // desired initial position, this will force proper controller reload @@ -740,7 +790,7 @@ - (void)loadView - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; - + // Uncomment the following code if you want the child controllers // to be loaded at this point. // @@ -751,10 +801,10 @@ - (void)viewDidAppear:(BOOL)animated // If you need to manipulate views of any of your child controllers in an override // of this method, you can load yourself the views explicitly on your overriden method. // However we discourage it as an app following the MVC principles should never need to do so - -// [_frontViewController view]; -// [_rearViewController view]; - + + // [_frontViewController view]; + // [_rearViewController view]; + // we store at this point the view's user interaction state as we may temporarily disable it // and resume it back to the previous state, it is possible to override this behaviour by // intercepting it on the panGestureBegan and panGestureEnded delegates @@ -762,14 +812,6 @@ - (void)viewDidAppear:(BOOL)animated } -- (NSUInteger)supportedInterfaceOrientations -{ - // we could have simply not implemented this, but we choose to call super to make explicit that we - // want the default behavior. - return [super supportedInterfaceOrientations]; -} - - #pragma mark - Public methods and property accessors - (void)setFrontViewController:(UIViewController *)frontViewController @@ -815,7 +857,7 @@ - (void)setRearViewController:(UIViewController *)rearViewController animated:(B [self _performTransitionOperation:SWRevealControllerOperationReplaceRearController withViewController:rearViewController animated:NO]; return; } - + [self _dispatchTransitionOperation:SWRevealControllerOperationReplaceRearController withViewController:rearViewController animated:animated]; } @@ -833,7 +875,7 @@ - (void)setRightViewController:(UIViewController *)rightViewController animated: [self _performTransitionOperation:SWRevealControllerOperationReplaceRightController withViewController:rightViewController animated:NO]; return; } - + [self _dispatchTransitionOperation:SWRevealControllerOperationReplaceRightController withViewController:rightViewController animated:animated]; } @@ -923,7 +965,7 @@ - (UITapGestureRecognizer*)tapGestureRecognizer if ( _tapGestureRecognizer == nil ) { UITapGestureRecognizer *tapRecognizer = - [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_handleTapGesture:)]; + [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_handleTapGesture:)]; tapRecognizer.delegate = self; [_contentView.frontView addGestureRecognizer:tapRecognizer]; @@ -944,13 +986,13 @@ - (void)setClipsViewsToBounds:(BOOL)clipsViewsToBounds #pragma mark - Provided acction methods - (IBAction)revealToggle:(id)sender -{ +{ [self revealToggleAnimated:YES]; } - (IBAction)rightRevealToggle:(id)sender -{ +{ [self rightRevealToggleAnimated:YES]; } @@ -1044,7 +1086,7 @@ - (void)_getDragLocationx:(CGFloat*)xLocation progress:(CGFloat*)progress { UIView *frontView = _contentView.frontView; *xLocation = frontView.frame.origin.x; - + int symetry = *xLocation<0 ? -1 : 1; CGFloat xWidth = symetry < 0 ? _rightViewRevealWidth : _rearViewRevealWidth; @@ -1057,7 +1099,7 @@ - (void)_getDragLocation:(CGFloat*)xLocation progress:(CGFloat*)progress overdra { UIView *frontView = _contentView.frontView; *xLocation = frontView.frame.origin.x; - + int symetry = *xLocation<0 ? -1 : 1; CGFloat xWidth = symetry < 0 ? _rightViewRevealWidth : _rearViewRevealWidth; @@ -1079,20 +1121,26 @@ - (void)_getDragLocation:(CGFloat*)xLocation progress:(CGFloat*)progress overdra // or executes the block right away if no pending requests are present. - (void)_enqueueBlock:(void (^)(void))block { - [_animationQueue insertObject:block atIndex:0]; - if ( _animationQueue.count == 1) + if ( _animationQueue.count >= 1) + { + void (^block2)(void) = [_animationQueue firstObject]; + [_animationQueue removeObjectAtIndex:0]; + block2(); + [self _enqueueBlock:block]; + }else { + [_animationQueue insertObject:block atIndex:0]; block(); } } // Removes the top most block in the queue and executes the following one if any. // Calls to this method must be paired with calls to _enqueueBlock, particularly it may be called -// from within a block passed to _enqueueBlock to remove itself when done with animations. +// from within a block passed to _enqueueBlock to remove itself when done with animations. - (void)_dequeue { [_animationQueue removeLastObject]; - + if ( _animationQueue.count > 0 ) { void (^block)(void) = [_animationQueue lastObject]; @@ -1113,8 +1161,13 @@ - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)recognizer if ( recognizer == _tapGestureRecognizer ) return [self _tapGestureShouldBegin]; + }else + { + + [self _dequeue]; + return [self gestureRecognizerShouldBegin:recognizer]; } - + return NO; } @@ -1143,7 +1196,7 @@ - (BOOL)_tapGestureShouldBegin if ( _frontViewPosition == FrontViewPositionLeft || _frontViewPosition == FrontViewPositionRightMostRemoved || _frontViewPosition == FrontViewPositionLeftSideMostRemoved ) - return NO; + return NO; // forbid gesture if the following delegate is implemented and returns NO if ( [_delegate respondsToSelector:@selector(revealControllerTapGestureShouldBegin:)] ) @@ -1159,27 +1212,27 @@ - (BOOL)_panGestureShouldBegin // forbid gesture if the initial translation is not horizontal UIView *recognizerView = _panGestureRecognizer.view; CGPoint translation = [_panGestureRecognizer translationInView:recognizerView]; -// NSLog( @"translation:%@", NSStringFromCGPoint(translation) ); -// if ( fabs(translation.y/translation.x) > 1 ) -// return NO; - + // NSLog( @"translation:%@", NSStringFromCGPoint(translation) ); + // if ( fabs(translation.y/translation.x) > 1 ) + // return NO; + // forbid gesture if the following delegate is implemented and returns NO if ( [_delegate respondsToSelector:@selector(revealControllerPanGestureShouldBegin:)] ) if ( [_delegate revealControllerPanGestureShouldBegin:self] == NO ) return NO; - + CGFloat xLocation = [_panGestureRecognizer locationInView:recognizerView].x; CGFloat width = recognizerView.bounds.size.width; BOOL draggableBorderAllowing = ( - /*_frontViewPosition != FrontViewPositionLeft ||*/ _draggableBorderWidth == 0.0f || - (_rearViewController && xLocation <= _draggableBorderWidth) || - (_rightViewController && xLocation >= (width - _draggableBorderWidth)) ); + /*_frontViewPosition != FrontViewPositionLeft ||*/ _draggableBorderWidth == 0.0f || + (_rearViewController && xLocation <= _draggableBorderWidth) || + (_rightViewController && xLocation >= (width - _draggableBorderWidth)) ); BOOL translationForbidding = ( _frontViewPosition == FrontViewPositionLeft && - ((_rearViewController == nil && translation.x > 0) || (_rightViewController == nil && translation.x < 0)) ); - + ((_rearViewController == nil && translation.x > 0) || (_rightViewController == nil && translation.x < 0)) ); + // allow gesture only within the bounds defined by the draggableBorderWidth property return draggableBorderAllowing && !translationForbidding ; } @@ -1211,7 +1264,7 @@ - (void)_handleRevealGesture:(UIPanGestureRecognizer *)recognizer break; case UIGestureRecognizerStateCancelled: - //case UIGestureRecognizerStateFailed: + //case UIGestureRecognizerStateFailed: [self _handleRevealGestureStateCancelledWithRecognizer:recognizer]; break; @@ -1228,10 +1281,10 @@ - (void)_handleRevealGestureStateBeganWithRecognizer:(UIPanGestureRecognizer *)r // the gesture, so we just enqueue a dummy block to ensure any programatic acctions will be // scheduled after the gesture is completed [self _enqueueBlock:^{}]; // <-- dummy block - + // we store the initial position and initialize a target position _panInitialFrontPosition = _frontViewPosition; - + // we disable user interactions on the views, however programatic accions will still be // enqueued to be performed after the gesture completes [self _disableUserInteraction]; @@ -1291,7 +1344,7 @@ - (void)_handleRevealGestureStateEndedWithRecognizer:(UIPanGestureRecognizer *)r // initially we assume drag to left and default duration FrontViewPosition frontViewPosition = FrontViewPositionLeft; NSTimeInterval duration = _toggleAnimationDuration; - + // Velocity driven change: if (ABS(velocity) > _quickFlickVelocity) { @@ -1316,8 +1369,8 @@ - (void)_handleRevealGestureStateEndedWithRecognizer:(UIPanGestureRecognizer *)r // Position driven change: else - { - // we may need to set the drag position + { + // we may need to set the drag position if (xLocation > revealWidth*0.5f) { frontViewPosition = FrontViewPositionRight; @@ -1325,7 +1378,7 @@ - (void)_handleRevealGestureStateEndedWithRecognizer:(UIPanGestureRecognizer *)r { if (bounceBack) frontViewPosition = FrontViewPositionLeft; - + else if (stableDrag && xLocation > revealWidth+revealOverdraw*0.5f) frontViewPosition = FrontViewPositionRightMost; } @@ -1343,7 +1396,7 @@ - (void)_handleRevealGestureStateEndedWithRecognizer:(UIPanGestureRecognizer *)r - (void)_handleRevealGestureStateCancelledWithRecognizer:(UIPanGestureRecognizer *)recognizer -{ +{ [self _restoreUserInteraction]; [self _notifyPanGestureEnded]; [self _dequeue]; @@ -1410,7 +1463,7 @@ - (void)_setFrontViewPosition:(FrontViewPosition)newPosition withDuration:(NSTim // We call the layoutSubviews method on the contentView view and send a delegate, which will // occur inside of an animation block if any animated transition is being performed [_contentView layoutSubviews]; - + if ([_delegate respondsToSelector:@selector(revealController:animateToPosition:)]) [_delegate revealController:self animateToPosition:_frontViewPosition]; }; @@ -1428,12 +1481,12 @@ - (void)_setFrontViewPosition:(FrontViewPosition)newPosition withDuration:(NSTim if ( _toggleAnimationType == SWRevealToggleAnimationTypeEaseOut ) { [UIView animateWithDuration:duration delay:0.0 - options:UIViewAnimationOptionCurveEaseOut animations:animations completion:completion]; + options:UIViewAnimationOptionCurveEaseOut animations:animations completion:completion]; } else { [UIView animateWithDuration:_toggleAnimationDuration delay:0.0 usingSpringWithDamping:_springDampingRatio initialSpringVelocity:1/duration - options:0 animations:animations completion:completion]; + options:0 animations:animations completion:completion]; } } else @@ -1450,7 +1503,7 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV { if ( [_delegate respondsToSelector:@selector(revealController:willAddViewController:forOperation:animated:)] ) [_delegate revealController:self willAddViewController:new forOperation:operation animated:animated]; - + UIViewController *old = nil; UIView *view = nil; @@ -1462,7 +1515,7 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV else if ( operation == SWRevealControllerOperationReplaceRightController ) old = _rightViewController, _rightViewController = new, view = _contentView.rightView; - + void (^completion)() = [self _transitionFromViewController:old toViewController:new inView:view]; void (^animationCompletion)() = ^ @@ -1470,23 +1523,23 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV completion(); if ( [_delegate respondsToSelector:@selector(revealController:didAddViewController:forOperation:animated:)] ) [_delegate revealController:self didAddViewController:new forOperation:operation animated:animated]; - + [self _dequeue]; }; if ( animated ) { id animationController = nil; - + if ( [_delegate respondsToSelector:@selector(revealController:animationControllerForOperation:fromViewController:toViewController:)] ) animationController = [_delegate revealController:self animationControllerForOperation:operation fromViewController:old toViewController:new]; - + if ( !animationController ) animationController = [[SWDefaultAnimationController alloc] initWithDuration:_replaceViewAnimationDuration]; - + SWContextTransitionObject *transitioningObject = [[SWContextTransitionObject alloc] initWithRevealController:self containerView:view - fromVC:old toVC:new completion:animationCompletion]; - + fromVC:old toVC:new completion:animationCompletion]; + if ( [animationController transitionDuration:transitioningObject] > 0 ) [animationController animateTransition:transitioningObject]; else @@ -1506,21 +1559,32 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV - (void (^)(void))_frontViewDeploymentForNewFrontViewPosition:(FrontViewPosition)newPosition { if ( (_rightViewController == nil && newPosition < FrontViewPositionLeft) || - (_rearViewController == nil && newPosition > FrontViewPositionLeft) ) + (_rearViewController == nil && newPosition > FrontViewPositionLeft) ) newPosition = FrontViewPositionLeft; BOOL positionIsChanging = (_frontViewPosition != newPosition); BOOL appear = - (_frontViewPosition >= FrontViewPositionRightMostRemoved || _frontViewPosition <= FrontViewPositionLeftSideMostRemoved || _frontViewPosition == FrontViewPositionNone) && - (newPosition < FrontViewPositionRightMostRemoved && newPosition > FrontViewPositionLeftSideMostRemoved); + (_frontViewPosition >= FrontViewPositionRightMostRemoved || _frontViewPosition <= FrontViewPositionLeftSideMostRemoved || _frontViewPosition == FrontViewPositionNone) && + (newPosition < FrontViewPositionRightMostRemoved && newPosition > FrontViewPositionLeftSideMostRemoved); BOOL disappear = - (newPosition >= FrontViewPositionRightMostRemoved || newPosition <= FrontViewPositionLeftSideMostRemoved ) && - (_frontViewPosition < FrontViewPositionRightMostRemoved && _frontViewPosition > FrontViewPositionLeftSideMostRemoved && _frontViewPosition != FrontViewPositionNone); + (newPosition >= FrontViewPositionRightMostRemoved || newPosition <= FrontViewPositionLeftSideMostRemoved ) && + (_frontViewPosition < FrontViewPositionRightMostRemoved && _frontViewPosition > FrontViewPositionLeftSideMostRemoved && _frontViewPosition != FrontViewPositionNone); if ( positionIsChanging ) { + if(_rearViewWillDisplayOverFrontView) + { + if(newPosition == FrontViewPositionLeft || newPosition == FrontViewPositionLeftSide) + [_contentView bringSubviewToFront:_contentView.frontView]; + else if(newPosition == FrontViewPositionRight || newPosition == FrontViewPositionRightMost) + { + [_contentView sendSubviewToBack:_contentView.frontView]; + [_contentView sendSubviewToBack:_contentView.rightView]; + } + } + if ( [_delegate respondsToSelector:@selector(revealController:willMoveToPosition:)] ) [_delegate revealController:self willMoveToPosition:newPosition]; } @@ -1528,7 +1592,7 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV _frontViewPosition = newPosition; void (^deploymentCompletion)() = - [self _deploymentForViewController:_frontViewController inView:_contentView.frontView appear:appear disappear:disappear]; + [self _deploymentForViewController:_frontViewController inView:_contentView.frontView appear:appear disappear:disappear]; void (^completion)() = ^() { @@ -1539,7 +1603,7 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV [_delegate revealController:self didMoveToPosition:newPosition]; } }; - + return completion; } @@ -1552,7 +1616,7 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV if ( _rearViewController == nil && newPosition > FrontViewPositionLeft ) newPosition = FrontViewPositionLeft; - + BOOL appear = (_rearViewPosition <= FrontViewPositionLeft || _rearViewPosition == FrontViewPositionNone) && newPosition > FrontViewPositionLeft; BOOL disappear = newPosition <= FrontViewPositionLeft && (_rearViewPosition > FrontViewPositionLeft && _rearViewPosition != FrontViewPositionNone); @@ -1562,7 +1626,7 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV _rearViewPosition = newPosition; void (^deploymentCompletion)() = - [self _deploymentForViewController:_rearViewController inView:_contentView.rearView appear:appear disappear:disappear]; + [self _deploymentForViewController:_rearViewController inView:_contentView.rearView appear:appear disappear:disappear]; void (^completion)() = ^() { @@ -1580,7 +1644,7 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV { if ( _rightViewController == nil && newPosition < FrontViewPositionLeft ) newPosition = FrontViewPositionLeft; - + BOOL appear = (_rightViewPosition >= FrontViewPositionLeft || _rightViewPosition == FrontViewPositionNone) && newPosition < FrontViewPositionLeft ; BOOL disappear = newPosition >= FrontViewPositionLeft && (_rightViewPosition < FrontViewPositionLeft && _rightViewPosition != FrontViewPositionNone); @@ -1590,7 +1654,7 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV _rightViewPosition = newPosition; void (^deploymentCompletion)() = - [self _deploymentForViewController:_rightViewController inView:_contentView.rightView appear:appear disappear:disappear]; + [self _deploymentForViewController:_rightViewController inView:_contentView.rightView appear:appear disappear:disappear]; void (^completion)() = ^() { @@ -1598,7 +1662,7 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV if ( disappear ) [_contentView unloadRightView]; }; - + return completion; } @@ -1652,11 +1716,12 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV { if (!controller) return ^(void){}; - + // nothing to do before completion at this stage void (^completionBlock)(void) = ^(void) { + //if(!_rearViewWillDisplayOverFrontView) [controller.view removeFromSuperview]; }; @@ -1798,7 +1863,7 @@ - (void)decodeRestorableStateWithCoder:(NSCoder *)coder _draggableBorderWidth = [coder decodeDoubleForKey:@"_draggableBorderWidth"]; _clipsViewsToBounds = [coder decodeBoolForKey:@"_clipsViewsToBounds"]; _extendsPointInsideHit = [coder decodeBoolForKey:@"_extendsPointInsideHit"]; - + [self setRearViewController:[coder decodeObjectForKey:@"_rearViewController"]]; [self setFrontViewController:[coder decodeObjectForKey:@"_frontViewController"]]; [self setRightViewController:[coder decodeObjectForKey:@"_rightViewController"]]; @@ -1814,6 +1879,59 @@ - (void)applicationFinishedRestoringState // nothing to do at this stage } +#pragma mark --RotateInterfaceAdjustments + +- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation +{ + return [self.frontViewController preferredInterfaceOrientationForPresentation]; +} + +- (UIInterfaceOrientationMask)supportedInterfaceOrientations +{ + return [self.frontViewController supportedInterfaceOrientations]; +} + +/*- (UIInterfaceOrientationMask)supportedInterfaceOrientations +{ + // we could have simply not implemented this, but we choose to call super to make explicit that we + // want the default behavior. + return [super supportedInterfaceOrientations]; +}*/ + +// Support for earlier than iOS 6.0 +#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000 +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + return YES; +} +#endif + +- (void)makeAdjustmentsForNewInterfaceOrientation +{ + //float w = [UIScreen mainScreen].bounds.size.width; + //float h = [UIScreen mainScreen].bounds.size.height; + //CGRect currentRect = CGRectMake(0, 0, w, h); + //_rearViewRevealWidth = currentRect.size.width - _rearViewRevealOverdraw; + //_rightViewRevealWidth = currentRect.size.width - _rightViewRevealOverdraw; + [self setFrontViewPosition:_frontViewPosition animated:YES]; +} + +- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration +{ + [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; +} + +- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation +{ + [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; + [self makeAdjustmentsForNewInterfaceOrientation]; +} + +- (BOOL)shouldAutorotate +{ + return [self.frontViewController shouldAutorotate]; +} + @end @@ -1903,7 +2021,7 @@ - (void)perform //{ // // This method is required for compatibility with SWRevealViewControllerSegue, now deprecated. // // It can be simply removed when using SWRevealViewControllerSegueSetController and SWRevealViewControlerSeguePushController -// +// // NSString *identifier = segue.identifier; // if ( [segue isKindOfClass:[SWRevealViewControllerSegue class]] && sender == nil ) // {