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..3f70e1a8 100644 --- a/RESideMenu/RESideMenu.h +++ b/RESideMenu/RESideMenu.h @@ -56,6 +56,9 @@ @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 (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 b2da249e..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 @@ -94,6 +96,9 @@ - (void)commonInit _scaleMenuView = YES; _fadeMenuView = YES; + _clipLeftMenuView = NO; + _clipRightMenuView = NO; + _parallaxEnabled = YES; _parallaxMenuMinimumRelativeValue = -15; _parallaxMenuMaximumRelativeValue = 15; @@ -256,7 +261,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; } @@ -281,6 +288,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); @@ -299,7 +311,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]; @@ -326,6 +343,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) { @@ -341,6 +363,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 +425,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; @@ -447,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; @@ -696,6 +772,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 - @@ -731,6 +816,10 @@ - (void)setContentViewController:(UIViewController *)contentViewController - (void)setLeftMenuViewController:(UIViewController *)leftMenuViewController { + if (self.clipLeftMenuView) { + leftMenuViewController.view.clipsToBounds = true; + } + if (!_leftMenuViewController) { _leftMenuViewController = leftMenuViewController; return; @@ -763,10 +852,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