Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
xcuserdata
Pods/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove your gitignore file

4 changes: 4 additions & 0 deletions RESideMenu/RESideMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
@property (assign, readwrite, nonatomic) UIStatusBarStyle menuPreferredStatusBarStyle;
@property (assign, readwrite, nonatomic) IBInspectable BOOL menuPrefersStatusBarHidden;

@property (assign, readonly, nonatomic, getter=isVisible) BOOL visible;
@property (assign, readonly, nonatomic, getter=isLeftMenuVisible) BOOL leftMenuVisible;
@property (assign, readonly, nonatomic, getter=isRightMenuVisible) BOOL rightMenuVisible;

- (id)initWithContentViewController:(UIViewController *)contentViewController
leftMenuViewController:(UIViewController *)leftMenuViewController
rightMenuViewController:(UIViewController *)rightMenuViewController;
Expand Down
73 changes: 59 additions & 14 deletions RESideMenu/RESideMenu.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
@interface RESideMenu ()

@property (strong, readwrite, nonatomic) UIImageView *backgroundImageView;
@property (assign, readwrite, nonatomic) BOOL visible;
@property (assign, readwrite, nonatomic) BOOL leftMenuVisible;
@property (assign, readwrite, nonatomic) BOOL rightMenuVisible;
@property (assign, readwrite, nonatomic, getter=isVisible) BOOL visible;
@property (assign, readwrite, nonatomic, getter=isLeftMenuVisible) BOOL leftMenuVisible;
@property (assign, readwrite, nonatomic, getter=isRightMenuVisible) BOOL rightMenuVisible;
@property (assign, readwrite, nonatomic) CGPoint originalPoint;
@property (strong, readwrite, nonatomic) UIButton *contentButton;
@property (strong, readwrite, nonatomic) UIView *menuViewContainer;
Expand Down Expand Up @@ -269,6 +269,11 @@ - (void)presentMenuViewContainerWithMenuViewController:(UIViewController *)menuV
}

- (void)showLeftMenuViewController
{
[self __showLeftMenuViewControllerWithVelocity:0];
}

- (void)__showLeftMenuViewControllerWithVelocity:(CGFloat)velocity
{
if (!self.leftMenuViewController) {
return;
Expand All @@ -278,9 +283,19 @@ - (void)showLeftMenuViewController
[self.view.window endEditing:YES];
[self addContentButton];
[self updateContentViewShadow];
[self resetContentViewScale];

[UIView animateWithDuration:self.animationDuration animations:^{
[self resetContentViewScale];

BOOL isLandscape = UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]);
CGFloat targetContentViewContainerCenterX = isLandscape ? self.contentViewInLandscapeOffsetCenterX + CGRectGetHeight(self.view.frame) : self.contentViewInPortraitOffsetCenterX + CGRectGetWidth(self.view.frame);
CGFloat distanceLeft = abs(self.contentViewContainer.center.x - targetContentViewContainerCenterX);
CGFloat initalSpringVelocity = distanceLeft > 0 ? velocity / distanceLeft : 0;

[UIView animateWithDuration:self.animationDuration
delay:0
usingSpringWithDamping:1
initialSpringVelocity:initalSpringVelocity
options:0
animations:^{
if (self.scaleContentView) {
self.contentViewContainer.transform = CGAffineTransformMakeScale(self.contentViewScaleValue, self.contentViewScaleValue);
} else {
Expand Down Expand Up @@ -313,6 +328,11 @@ - (void)showLeftMenuViewController
}

- (void)showRightMenuViewController
{
[self __showRightMenuViewControllerWithVelocity:0];
}

- (void)__showRightMenuViewControllerWithVelocity:(CGFloat)velocity
{
if (!self.rightMenuViewController) {
return;
Expand All @@ -322,16 +342,26 @@ - (void)showRightMenuViewController
[self.view.window endEditing:YES];
[self addContentButton];
[self updateContentViewShadow];
[self resetContentViewScale];

[self resetContentViewScale];

BOOL isLandscape = UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]);
CGFloat targetContentViewContainerCenterX = isLandscape ? -self.contentViewInLandscapeOffsetCenterX : -self.contentViewInPortraitOffsetCenterX;
CGFloat distanceLeft = abs(self.contentViewContainer.center.x - targetContentViewContainerCenterX);
CGFloat initalSpringVelocity = distanceLeft > 0 ? velocity / distanceLeft : 0;

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[UIView animateWithDuration:self.animationDuration animations:^{
[UIView animateWithDuration:self.animationDuration
delay:0
usingSpringWithDamping:1
initialSpringVelocity:initalSpringVelocity
options:0
animations:^{
if (self.scaleContentView) {
self.contentViewContainer.transform = CGAffineTransformMakeScale(self.contentViewScaleValue, self.contentViewScaleValue);
} else {
self.contentViewContainer.transform = CGAffineTransformIdentity;
}
self.contentViewContainer.center = CGPointMake((UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) ? -self.contentViewInLandscapeOffsetCenterX : -self.contentViewInPortraitOffsetCenterX), self.contentViewContainer.center.y);
self.contentViewContainer.center = CGPointMake(targetContentViewContainerCenterX, self.contentViewContainer.center.y);

self.menuViewContainer.alpha = !self.fadeMenuView ?: 1.0f;
self.menuViewContainer.transform = CGAffineTransformIdentity;
Expand Down Expand Up @@ -360,6 +390,11 @@ - (void)hideViewController:(UIViewController *)viewController
}

- (void)hideMenuViewControllerAnimated:(BOOL)animated
{
[self hideMenuViewControllerAnimated:animated withVelocity:0];
}

- (void)hideMenuViewControllerAnimated:(BOOL)animated withVelocity:(CGFloat)velocity
{
BOOL rightMenuVisible = self.rightMenuVisible;
if ([self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:willHideMenuViewController:)]) {
Expand Down Expand Up @@ -405,8 +440,17 @@ - (void)hideMenuViewControllerAnimated:(BOOL)animated
};

if (animated) {
CGFloat targetContentViewContainerCenterX = self.view.center.x;
CGFloat distanceLeft = abs(self.contentViewContainer.center.x - targetContentViewContainerCenterX);
CGFloat initalSpringVelocity = distanceLeft > 0 ? velocity / distanceLeft : 0;

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[UIView animateWithDuration:self.animationDuration animations:^{
[UIView animateWithDuration:self.animationDuration
delay:0
usingSpringWithDamping:1
initialSpringVelocity:initalSpringVelocity
options:0
animations:^{
animationBlock();
} completion:^(BOOL finished) {
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
Expand Down Expand Up @@ -671,9 +715,10 @@ - (void)panGestureRecognized:(UIPanGestureRecognizer *)recognizer
[self hideMenuViewControllerAnimated:NO];
}
else {
if ([recognizer velocityInView:self.view].x > 0) {
CGFloat velocityX = [recognizer velocityInView:self.view].x;
if (velocityX > 0) {
if (self.contentViewContainer.frame.origin.x < 0) {
[self hideMenuViewController];
[self hideMenuViewControllerAnimated:YES withVelocity:velocityX];
} else {
if (self.leftMenuViewController) {
[self showLeftMenuViewController];
Expand All @@ -685,7 +730,7 @@ - (void)panGestureRecognized:(UIPanGestureRecognizer *)recognizer
[self showRightMenuViewController];
}
} else {
[self hideMenuViewController];
[self hideMenuViewControllerAnimated:YES withVelocity:-velocityX];
}
}
}
Expand Down