From fe6a8d0e79f4a9d8a942e20fba1becac1ae53c9b Mon Sep 17 00:00:00 2001 From: Alexey Hippie Date: Tue, 10 Feb 2015 20:30:11 +0300 Subject: [PATCH 1/4] Clip MenuView feature; --- RESideMenu/RECommonFunctions.m | 2 ++ RESideMenu/RESideMenu.h | 2 ++ RESideMenu/RESideMenu.m | 51 +++++++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/RESideMenu/RECommonFunctions.m b/RESideMenu/RECommonFunctions.m index 1cfc8207..5d8266a0 100755 --- a/RESideMenu/RECommonFunctions.m +++ b/RESideMenu/RECommonFunctions.m @@ -23,6 +23,8 @@ // THE SOFTWARE. // +#import +#import #import "RECommonFunctions.h" BOOL RESideMenuUIKitIsFlatMode(void) diff --git a/RESideMenu/RESideMenu.h b/RESideMenu/RESideMenu.h index 6682ae1b..5d005c55 100644 --- a/RESideMenu/RESideMenu.h +++ b/RESideMenu/RESideMenu.h @@ -56,6 +56,8 @@ @property (assign, readwrite, nonatomic) IBInspectable BOOL scaleBackgroundImageView; @property (assign, readwrite, nonatomic) IBInspectable BOOL scaleMenuView; @property (assign, readwrite, nonatomic) IBInspectable BOOL contentViewShadowEnabled; +@property (assign, readwrite, nonatomic) IBInspectable BOOL clipLeftMenuView; +@property (assign, readwrite, nonatomic) IBInspectable BOOL clipRightMenuView; @property (strong, readwrite, nonatomic) IBInspectable UIColor *contentViewShadowColor; @property (assign, readwrite, nonatomic) IBInspectable CGSize contentViewShadowOffset; @property (assign, readwrite, nonatomic) IBInspectable CGFloat contentViewShadowOpacity; diff --git a/RESideMenu/RESideMenu.m b/RESideMenu/RESideMenu.m index b2da249e..3b02c85c 100644 --- a/RESideMenu/RESideMenu.m +++ b/RESideMenu/RESideMenu.m @@ -94,6 +94,9 @@ - (void)commonInit _scaleMenuView = YES; _fadeMenuView = YES; + _clipLeftMenuView = NO; + _clipRightMenuView = NO; + _parallaxEnabled = YES; _parallaxMenuMinimumRelativeValue = -15; _parallaxMenuMaximumRelativeValue = 15; @@ -299,7 +302,12 @@ - (void)showLeftMenuViewController self.menuViewContainer.transform = CGAffineTransformIdentity; if (self.scaleBackgroundImageView) self.backgroundImageView.transform = CGAffineTransformIdentity; - + + if (self.clipLeftMenuView) { + CGFloat finalWidth = self.view.frame.size.width / 2.0 + self.contentViewInPortraitOffsetCenterX; + self.menuViewContainer.frame = CGRectMake(0.0, 0.0, finalWidth, self.view.bounds.size.height); + } + } completion:^(BOOL finished) { [self addContentViewControllerMotionEffects]; @@ -341,6 +349,11 @@ - (void)showRightMenuViewController if (self.scaleBackgroundImageView) self.backgroundImageView.transform = CGAffineTransformIdentity; + if (self.clipRightMenuView) { + CGFloat finalWidth = self.view.frame.size.width / 2.0 + self.contentViewInPortraitOffsetCenterX; + self.menuViewContainer.frame = CGRectMake(self.view.frame.size.width - finalWidth, 0.0, finalWidth, self.view.bounds.size.height); + } + } completion:^(BOOL finished) { if (!self.rightMenuVisible && [self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:didShowMenuViewController:)]) { [self.delegate sideMenu:self didShowMenuViewController:self.rightMenuViewController]; @@ -398,6 +411,11 @@ - (void)hideMenuViewControllerAnimated:(BOOL)animated } ); } + + if (self.clipLeftMenuView || self.clipRightMenuView) { + strongSelf.menuViewContainer.frame = CGRectMake(0.0, 0.0, 0.0, self.view.bounds.size.height); + } + }; void (^completionBlock)(void) = ^{ __typeof (weakSelf) __strong strongSelf = weakSelf; @@ -696,6 +714,15 @@ - (void)panGestureRecognized:(UIPanGestureRecognizer *)recognizer } } } + + if (self.leftMenuViewController && self.clipLeftMenuView) { + CGFloat width = self.contentViewContainer.frame.origin.x; + self.menuViewContainer.frame = CGRectMake(0.0, 0.0, width, self.view.bounds.size.height); + } + if (self.rightMenuViewController && self.clipRightMenuView) { + CGFloat width = - self.contentViewContainer.frame.origin.x; + self.menuViewContainer.frame = CGRectMake(self.view.frame.size.width - width, 0.0, width, self.view.bounds.size.height); + } } #pragma mark - @@ -744,6 +771,10 @@ - (void)setLeftMenuViewController:(UIViewController *)leftMenuViewController [self.menuViewContainer addSubview:self.leftMenuViewController.view]; [self.leftMenuViewController didMoveToParentViewController:self]; + if (self.clipLeftMenuView) { + self.leftMenuViewController.view.clipsToBounds = true; + } + [self addMenuViewControllerMotionEffects]; [self.view bringSubviewToFront:self.contentViewContainer]; } @@ -763,10 +794,28 @@ - (void)setRightMenuViewController:(UIViewController *)rightMenuViewController [self.menuViewContainer addSubview:self.rightMenuViewController.view]; [self.rightMenuViewController didMoveToParentViewController:self]; + if (self.rightMenuViewController) { + self.rightMenuViewController.view.clipsToBounds = true; + } + [self addMenuViewControllerMotionEffects]; [self.view bringSubviewToFront:self.contentViewContainer]; } +- (void)setClipLeftMenuView:(BOOL)clipLeftMenuView { + _clipLeftMenuView = clipLeftMenuView; + if (self.leftMenuViewController) { + self.leftMenuViewController.view.clipsToBounds = clipLeftMenuView; + } +} + +- (void)setClipRightMenuView:(BOOL)clipRightMenuView { + _clipRightMenuView = clipRightMenuView; + if (self.rightMenuViewController) { + self.rightMenuViewController.view.clipsToBounds = clipRightMenuView; + } +} + #pragma mark - #pragma mark View Controller Rotation handler From 20f95628376aeb837f3c9e765ba2a4d6da23a189 Mon Sep 17 00:00:00 2001 From: Alexey Hippie Date: Tue, 10 Feb 2015 20:50:14 +0300 Subject: [PATCH 2/4] Fixing assigning view after property; --- RESideMenu/RESideMenu.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/RESideMenu/RESideMenu.m b/RESideMenu/RESideMenu.m index 3b02c85c..a8f8c38b 100644 --- a/RESideMenu/RESideMenu.m +++ b/RESideMenu/RESideMenu.m @@ -758,6 +758,10 @@ - (void)setContentViewController:(UIViewController *)contentViewController - (void)setLeftMenuViewController:(UIViewController *)leftMenuViewController { + if (self.clipLeftMenuView) { + leftMenuViewController.view.clipsToBounds = true; + } + if (!_leftMenuViewController) { _leftMenuViewController = leftMenuViewController; return; @@ -771,10 +775,6 @@ - (void)setLeftMenuViewController:(UIViewController *)leftMenuViewController [self.menuViewContainer addSubview:self.leftMenuViewController.view]; [self.leftMenuViewController didMoveToParentViewController:self]; - if (self.clipLeftMenuView) { - self.leftMenuViewController.view.clipsToBounds = true; - } - [self addMenuViewControllerMotionEffects]; [self.view bringSubviewToFront:self.contentViewContainer]; } From 92e17b0cc7e58b7bbf3c25a9699fc9dbda9abf8c Mon Sep 17 00:00:00 2001 From: Alexey Hippie Date: Tue, 10 Feb 2015 21:59:23 +0300 Subject: [PATCH 3/4] Fixes for opening menu bar from presentMenuViewContainerWithMenuViewController: --- RESideMenu/RESideMenu.m | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/RESideMenu/RESideMenu.m b/RESideMenu/RESideMenu.m index a8f8c38b..256b9f7e 100644 --- a/RESideMenu/RESideMenu.m +++ b/RESideMenu/RESideMenu.m @@ -259,7 +259,9 @@ - (void)presentMenuViewContainerWithMenuViewController:(UIViewController *)menuV self.backgroundImageView.transform = CGAffineTransformIdentity; self.backgroundImageView.frame = self.view.bounds; } - self.menuViewContainer.frame = self.view.bounds; + if (!self.clipLeftMenuView) { + self.menuViewContainer.frame = self.view.bounds; + } if (self.scaleMenuView) { self.menuViewContainer.transform = self.menuViewControllerTransformation; } @@ -284,6 +286,11 @@ - (void)showLeftMenuViewController [self updateContentViewShadow]; [self resetContentViewScale]; + if (self.clipLeftMenuView) { + CGFloat width = self.contentViewContainer.frame.origin.x; + self.menuViewContainer.frame = CGRectMake(0.0, 0.0, width, self.view.bounds.size.height); + } + [UIView animateWithDuration:self.animationDuration animations:^{ if (self.scaleContentView) { self.contentViewContainer.transform = CGAffineTransformMakeScale(self.contentViewScaleValue, self.contentViewScaleValue); @@ -334,6 +341,11 @@ - (void)showRightMenuViewController [self updateContentViewShadow]; [self resetContentViewScale]; + if (self.clipRightMenuView) { + CGFloat width = - self.contentViewContainer.frame.origin.x; + self.menuViewContainer.frame = CGRectMake(self.view.frame.size.width - width, 0.0, width, self.view.bounds.size.height); + } + [[UIApplication sharedApplication] beginIgnoringInteractionEvents]; [UIView animateWithDuration:self.animationDuration animations:^{ if (self.scaleContentView) { From 85ac0848dff64a508faa7faf0dabdb9f11bbabfc Mon Sep 17 00:00:00 2001 From: Alexey Hippie Date: Wed, 11 Feb 2015 13:51:08 +0300 Subject: [PATCH 4/4] Clipping shadows under content view; --- RESideMenu/RESideMenu.h | 1 + RESideMenu/RESideMenu.m | 50 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/RESideMenu/RESideMenu.h b/RESideMenu/RESideMenu.h index 5d005c55..3f70e1a8 100644 --- a/RESideMenu/RESideMenu.h +++ b/RESideMenu/RESideMenu.h @@ -58,6 +58,7 @@ @property (assign, readwrite, nonatomic) IBInspectable BOOL contentViewShadowEnabled; @property (assign, readwrite, nonatomic) IBInspectable BOOL clipLeftMenuView; @property (assign, readwrite, nonatomic) IBInspectable BOOL clipRightMenuView; +@property (assign, readwrite, nonatomic) IBInspectable BOOL contentViewClipShadowUnderView; @property (strong, readwrite, nonatomic) IBInspectable UIColor *contentViewShadowColor; @property (assign, readwrite, nonatomic) IBInspectable CGSize contentViewShadowOffset; @property (assign, readwrite, nonatomic) IBInspectable CGFloat contentViewShadowOpacity; diff --git a/RESideMenu/RESideMenu.m b/RESideMenu/RESideMenu.m index 256b9f7e..24ec1cd4 100644 --- a/RESideMenu/RESideMenu.m +++ b/RESideMenu/RESideMenu.m @@ -37,6 +37,8 @@ @interface RESideMenu () @property (strong, readwrite, nonatomic) UIButton *contentButton; @property (strong, readwrite, nonatomic) UIView *menuViewContainer; @property (strong, readwrite, nonatomic) UIView *contentViewContainer; +@property (strong, readwrite, nonatomic) UIView *leftShadowView; +@property (strong, readwrite, nonatomic) UIView *rightShadowView; @property (assign, readwrite, nonatomic) BOOL didNotifyDelegate; @end @@ -477,8 +479,52 @@ - (void)statusBarNeedsAppearanceUpdate - (void)updateContentViewShadow { if (self.contentViewShadowEnabled) { - CALayer *layer = self.contentViewContainer.layer; - UIBezierPath *path = [UIBezierPath bezierPathWithRect:layer.bounds]; + + UIBezierPath *path = nil; + CALayer *layer = nil; + + if (self.contentViewClipShadowUnderView) { + if (self.leftMenuViewController) { + if (!self.leftShadowView) { + // Create shadow view + UIView *shadowView = [UIView new]; + shadowView.backgroundColor = [UIColor clearColor]; + shadowView.frame = CGRectMake(- (self.contentViewShadowRadius + 1) * 2, 0, (self.contentViewShadowRadius + 1) * 2, self.contentViewContainer.frame.size.height); + shadowView.clipsToBounds = YES; + [self.contentViewContainer addSubview:shadowView]; + self.leftShadowView = shadowView; + } + + CGRect shadowRect = self.contentViewContainer.bounds; + shadowRect.origin.x = self.leftShadowView.frame.size.width; + path = [UIBezierPath bezierPathWithRect:shadowRect]; + layer = self.leftShadowView.layer; + } + + if (self.rightMenuViewController) { + if (!self.rightShadowView) { + // Create shadow view + UIView *shadowView = [UIView new]; + shadowView.backgroundColor = [UIColor clearColor]; + shadowView.frame = CGRectMake(self.contentViewContainer.frame.size.width, + 0, + (self.contentViewShadowRadius + 1) * 2, + self.contentViewContainer.frame.size.height); + shadowView.clipsToBounds = YES; + [self.contentViewContainer addSubview:shadowView]; + self.leftShadowView = shadowView; + } + + CGRect shadowRect = self.contentViewContainer.bounds; + shadowRect.origin.x = -self.contentViewContainer.frame.size.width; + path = [UIBezierPath bezierPathWithRect:shadowRect]; + layer = self.rightShadowView.layer; + } + } else { + path = [UIBezierPath bezierPathWithRect:layer.bounds]; + layer = self.contentViewContainer.layer; + } + layer.shadowPath = path.CGPath; layer.shadowColor = self.contentViewShadowColor.CGColor; layer.shadowOffset = self.contentViewShadowOffset;