Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clip MenuView feature; #215

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RESideMenu/RECommonFunctions.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
// THE SOFTWARE.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "RECommonFunctions.h"

BOOL RESideMenuUIKitIsFlatMode(void)
Expand Down
3 changes: 3 additions & 0 deletions RESideMenu/RESideMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
115 changes: 111 additions & 4 deletions RESideMenu/RESideMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -94,6 +96,9 @@ - (void)commonInit
_scaleMenuView = YES;
_fadeMenuView = YES;

_clipLeftMenuView = NO;
_clipRightMenuView = NO;

_parallaxEnabled = YES;
_parallaxMenuMinimumRelativeValue = -15;
_parallaxMenuMaximumRelativeValue = 15;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand All @@ -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];

Expand All @@ -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) {
Expand All @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 -
Expand Down Expand Up @@ -731,6 +816,10 @@ - (void)setContentViewController:(UIViewController *)contentViewController

- (void)setLeftMenuViewController:(UIViewController *)leftMenuViewController
{
if (self.clipLeftMenuView) {
leftMenuViewController.view.clipsToBounds = true;
}

if (!_leftMenuViewController) {
_leftMenuViewController = leftMenuViewController;
return;
Expand Down Expand Up @@ -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

Expand Down