diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..9983f9ec --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +xcuserdata +Pods/ \ No newline at end of file diff --git a/RESideMenu/RESideMenu.h b/RESideMenu/RESideMenu.h index 7e358035..89dfeac8 100644 --- a/RESideMenu/RESideMenu.h +++ b/RESideMenu/RESideMenu.h @@ -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; diff --git a/RESideMenu/RESideMenu.m b/RESideMenu/RESideMenu.m old mode 100644 new mode 100755 index fca46701..9094414d --- a/RESideMenu/RESideMenu.m +++ b/RESideMenu/RESideMenu.m @@ -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; @@ -269,6 +269,11 @@ - (void)presentMenuViewContainerWithMenuViewController:(UIViewController *)menuV } - (void)showLeftMenuViewController +{ + [self __showLeftMenuViewControllerWithVelocity:0]; +} + +- (void)__showLeftMenuViewControllerWithVelocity:(CGFloat)velocity { if (!self.leftMenuViewController) { return; @@ -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 { @@ -313,6 +328,11 @@ - (void)showLeftMenuViewController } - (void)showRightMenuViewController +{ + [self __showRightMenuViewControllerWithVelocity:0]; +} + +- (void)__showRightMenuViewControllerWithVelocity:(CGFloat)velocity { if (!self.rightMenuViewController) { return; @@ -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; @@ -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:)]) { @@ -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]; @@ -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]; @@ -685,7 +730,7 @@ - (void)panGestureRecognized:(UIPanGestureRecognizer *)recognizer [self showRightMenuViewController]; } } else { - [self hideMenuViewController]; + [self hideMenuViewControllerAnimated:YES withVelocity:-velocityX]; } } }