diff --git a/SWRevealViewController/SWRevealViewController.h b/SWRevealViewController/SWRevealViewController.h index ae9c101..4e1b5aa 100755 --- a/SWRevealViewController/SWRevealViewController.h +++ b/SWRevealViewController/SWRevealViewController.h @@ -85,13 +85,13 @@ typedef enum // Toogles the current state of the front controller between Left or Right and fully visible // Use setFrontViewPosition to set a particular position - (void)revealToggleAnimated:(BOOL)animated; -- (void)rightRevealToggleAnimated:(BOOL)animated; +- (void)rightRevealToggleAnimated:(BOOL)animated; // <-- simetric implementation of the above for the rightViewController // The following methods are meant to be directly connected to the action method of a button // to perform user triggered postion change of the controller views. This is ussually added to a // button on top left or right of the frontViewController - (void)revealToggle:(id)sender; -- (void)rightRevealToggle:(id)sender; +- (void)rightRevealToggle:(id)sender; // <-- simetric implementation of the above for the rightViewController // The following method will provide a panGestureRecognizer suitable to be added to any view on the frontController // in order to perform usual drag and swipe gestures on the frontViewController to reveal the rear views. This @@ -101,13 +101,17 @@ typedef enum // The following properties are provided for further customization, they are set to default values on initialization, // you should not generally have to set them -// Defines how much of the rear view is shown, default is 260. +// Defines how much of the rear or right view is shown, default is 260. @property (assign, nonatomic) CGFloat rearViewRevealWidth; -@property (assign, nonatomic) CGFloat rightViewRevealWidth; +@property (assign, nonatomic) CGFloat rightViewRevealWidth; // <-- simetric implementation of the above for the rightViewController // Defines how much of an overdraw can occur when dragging further than 'rearViewRevealWidth', default is 60. @property (assign, nonatomic) CGFloat rearViewRevealOverdraw; -@property (assign, nonatomic) CGFloat rightViewRevealOverdraw; +@property (assign, nonatomic) CGFloat rightViewRevealOverdraw; // <-- simetric implementation of the above for the rightViewController + +// Defines how much displacement is applied to the rear view when animating or dragging the front view, default is 40. +@property (assign, nonatomic) CGFloat rearViewRevealDisplacement; +@property (assign, nonatomic) CGFloat rightViewRevealDisplacement; // If YES (the default) the controller will bounce to the Left position when dragging further than 'rearViewRevealWidth' @property (assign, nonatomic) BOOL bounceBackOnOverdraw; @@ -115,7 +119,7 @@ typedef enum // If YES (default is NO) the controller will allow permanent dragging up to the rightMostPosition @property (assign, nonatomic) BOOL stableDragOnOverdraw; -@property (assign, nonatomic) BOOL stableDragOnLeftOverdraw; +@property (assign, nonatomic) BOOL stableDragOnLeftOverdraw; // <-- simetric implementation of the above for the rightViewController // Velocity required for the controller to toggle its state based on a swipe movement, default is 300 @property (assign, nonatomic) CGFloat quickFlickVelocity; @@ -129,6 +133,9 @@ typedef enum // Defines the radius of the front view's shadow offset default is {0.0f,2.5f} @property (assign, nonatomic) CGSize frontViewShadowOffset; +//Defines the front view's shadow opacity, default is 1.0f +@property (assign, nonatomic) CGFloat frontViewShadowOpacity; + // The class properly handles all the relevant calls to appearance methods on the contained controllers. // Moreover you can assign a delegate to let the class inform you on positions and animation activity. diff --git a/SWRevealViewController/SWRevealViewController.m b/SWRevealViewController/SWRevealViewController.m index 375857a..a9bf70b 100755 --- a/SWRevealViewController/SWRevealViewController.m +++ b/SWRevealViewController/SWRevealViewController.m @@ -122,6 +122,16 @@ - (void)_getAdjustedFrontViewPosition:(FrontViewPosition*)frontViewPosition forS @implementation SWRevealView + +static CGFloat scaledValue( CGFloat v1, CGFloat min2, CGFloat max2, CGFloat min1, CGFloat max1) +{ + CGFloat result = min2 + (v1-min1)*((max2-min2)/(max1-min1)); + if ( result != result ) return min2; // nan + if ( result < min2 ) return min2; + if ( result > max2 ) return max2; + return result; +} + - (id)initWithFrame:(CGRect)frame controller:(SWRevealViewController*)controller { self = [super initWithFrame:frame]; @@ -138,7 +148,8 @@ - (id)initWithFrame:(CGRect)frame controller:(SWRevealViewController*)controller CALayer *frontViewLayer = _frontView.layer; frontViewLayer.masksToBounds = NO; frontViewLayer.shadowColor = [UIColor blackColor].CGColor; - frontViewLayer.shadowOpacity = 1.0f; + //frontViewLayer.shadowOpacity = 1.0f; + frontViewLayer.shadowOpacity = _c.frontViewShadowOpacity; frontViewLayer.shadowOffset = _c.frontViewShadowOffset; frontViewLayer.shadowRadius = _c.frontViewShadowRadius; } @@ -151,12 +162,13 @@ - (void)layoutSubviews { if ( _disableLayout ) return; - [self _layoutRearViews]; - CGRect bounds = self.bounds; - CGFloat xPosition = [self frontLocationForPosition:_c.frontViewPosition]; - _frontView.frame = CGRectMake(xPosition, 0.0f, bounds.size.width, bounds.size.height); + CGFloat xLocation = [self frontLocationForPosition:_c.frontViewPosition]; + + [self _layoutRearViewsForLocation:xLocation]; + + _frontView.frame = CGRectMake(xLocation, 0.0f, bounds.size.width, bounds.size.height); UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:_frontView.bounds]; _frontView.layer.shadowPath = shadowPath.CGPath; @@ -171,7 +183,24 @@ - (void)prepareRearViewForPosition:(FrontViewPosition)newPosition _rearView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; [self insertSubview:_rearView belowSubview:_frontView]; } - [self _layoutRearViews]; + + CGFloat xLocation = [self frontLocationForPosition:_c.frontViewPosition]; + [self _layoutRearViewsForLocation:xLocation]; + [self _prepareForNewPosition:newPosition]; +} + + +- (void)prepareRightViewForPosition:(FrontViewPosition)newPosition +{ + if ( _rightView == nil ) + { + _rightView = [[UIView alloc] initWithFrame:self.bounds]; + _rightView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; + [self insertSubview:_rightView belowSubview:_frontView]; + } + + CGFloat xLocation = [self frontLocationForPosition:_c.frontViewPosition]; + [self _layoutRearViewsForLocation:xLocation]; [self _prepareForNewPosition:newPosition]; } @@ -197,38 +226,47 @@ - (CGFloat)frontLocationForPosition:(FrontViewPosition)frontViewPosition } -- (void)dragFrontViewToXPosition:(CGFloat)xPosition +- (void)dragFrontViewToXLocation:(CGFloat)xLocation { CGRect bounds = self.bounds; - xPosition = [self _adjustedDragLocationForLocation:xPosition]; - _frontView.frame = CGRectMake(xPosition, 0.0f, bounds.size.width, bounds.size.height); + + xLocation = [self _adjustedDragLocationForLocation:xLocation]; + [self _layoutRearViewsForLocation:xLocation]; + + _frontView.frame = CGRectMake(xLocation, 0.0f, bounds.size.width, bounds.size.height); } -- (void)prepareRightViewForPosition:(FrontViewPosition)newPosition -{ - if ( _rightView == nil ) - { - _rightView = [[UIView alloc] initWithFrame:self.bounds]; - _rightView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; - [self insertSubview:_rightView belowSubview:_frontView]; - } - [self _layoutRearViews]; - [self _prepareForNewPosition:newPosition]; -} +# pragma mark private +//- (void)_layoutRearViews +//{ +// CGRect bounds = self.bounds; +// +// CGFloat rearWidth = _c.rearViewRevealWidth + _c.rearViewRevealOverdraw; +// _rearView.frame = CGRectMake(0.0, 0.0, rearWidth, bounds.size.height); +// +// CGFloat rightWidth = _c.rightViewRevealWidth + _c.rightViewRevealOverdraw; +// _rightView.frame = CGRectMake(bounds.size.width-rightWidth, 0.0f, rightWidth, bounds.size.height); +//} -# pragma mark private -- (void)_layoutRearViews + +- (void)_layoutRearViewsForLocation:(CGFloat)xLocation { CGRect bounds = self.bounds; - CGFloat rearWidth = _c.rearViewRevealWidth + _c.rearViewRevealOverdraw; - _rearView.frame = CGRectMake(0.0, 0.0, rearWidth, bounds.size.height); + CGFloat rearRevealWidth = _c.rearViewRevealWidth; + CGFloat rearXLocation = scaledValue(xLocation, -_c.rearViewRevealDisplacement, 0, 0, rearRevealWidth); + + CGFloat rearWidth = rearRevealWidth + _c.rearViewRevealOverdraw; + _rearView.frame = CGRectMake(rearXLocation, 0.0, rearWidth, bounds.size.height); - CGFloat rightWidth = _c.rightViewRevealWidth + _c.rightViewRevealOverdraw; - _rightView.frame = CGRectMake(bounds.size.width-rightWidth, 0.0f, rightWidth, bounds.size.height); + CGFloat rightRevealWidth = _c.rightViewRevealWidth; + CGFloat rightXLocation = scaledValue(xLocation, 0, _c.rightViewRevealDisplacement, -rightRevealWidth, 0); + + CGFloat rightWidth = rightRevealWidth + _c.rightViewRevealOverdraw; + _rightView.frame = CGRectMake(bounds.size.width-rightWidth+rightXLocation, 0.0f, rightWidth, bounds.size.height); } @@ -349,8 +387,10 @@ - (void)_initDefaultProperties _rightViewPosition = FrontViewPositionLeft; _rearViewRevealWidth = 260.0f; _rearViewRevealOverdraw = 60.0f; + _rearViewRevealDisplacement = 40.0f; _rightViewRevealWidth = 260.0f; _rightViewRevealOverdraw = 60.0f; + _rightViewRevealDisplacement = 40.0f; _bounceBackOnOverdraw = YES; _bounceBackOnLeftOverdraw = YES; _stableDragOnOverdraw = NO; @@ -359,6 +399,7 @@ - (void)_initDefaultProperties _toggleAnimationDuration = 0.25; _frontViewShadowRadius = 2.5f; _frontViewShadowOffset = CGSizeMake(0.0f, 2.5f); + _frontViewShadowOpacity = 1.0f; _userInteractionStore = YES; _animationQueue = [NSMutableArray array]; } @@ -490,11 +531,12 @@ - (NSUInteger)supportedInterfaceOrientations } // Support for earlier than iOS 6.0 +#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - +#endif #pragma mark - Public methods and property accessors @@ -745,23 +787,23 @@ - (void)_handleRevealGestureStateChangedWithRecognizer:(UIPanGestureRecognizer * CGFloat translation = [recognizer translationInView:_contentView].x; CGFloat baseLocation = [_contentView frontLocationForPosition:_panInitialFrontPosition]; - CGFloat xPosition = baseLocation + translation; + CGFloat xLocation = baseLocation + translation; - if ( xPosition < 0 ) + if ( xLocation < 0 ) { - if ( _rightViewController == nil ) xPosition = 0; + if ( _rightViewController == nil ) xLocation = 0; [self _rightViewDeploymentForNewFrontViewPosition:FrontViewPositionLeftSide](); [self _rearViewDeploymentForNewFrontViewPosition:FrontViewPositionLeftSide](); } - if ( xPosition > 0 ) + if ( xLocation > 0 ) { - if ( _rearViewController == nil ) xPosition = 0; + if ( _rearViewController == nil ) xLocation = 0; [self _rightViewDeploymentForNewFrontViewPosition:FrontViewPositionRight](); [self _rearViewDeploymentForNewFrontViewPosition:FrontViewPositionRight](); } - [_contentView dragFrontViewToXPosition:xPosition]; + [_contentView dragFrontViewToXLocation:xLocation]; }