From 0d8c26584200e77da881fefe21b990c855c8d318 Mon Sep 17 00:00:00 2001 From: David Hart Date: Wed, 6 Aug 2014 15:27:03 +0200 Subject: [PATCH 1/3] Use gesture velocity in animation --- RESideMenu/RESideMenu.m | 74 +++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 14 deletions(-) mode change 100644 => 100755 RESideMenu/RESideMenu.m diff --git a/RESideMenu/RESideMenu.m b/RESideMenu/RESideMenu.m old mode 100644 new mode 100755 index 2efa2363..083fb825 --- a/RESideMenu/RESideMenu.m +++ b/RESideMenu/RESideMenu.m @@ -253,6 +253,11 @@ - (void)__presentMenuViewContainerWithMenuViewController:(UIViewController *)men } - (void)__showLeftMenuViewController +{ + [self __showLeftMenuViewControllerWithVelocity:0]; +} + +- (void)__showLeftMenuViewControllerWithVelocity:(CGFloat)velocity { if (!self.leftMenuViewController) { return; @@ -262,14 +267,25 @@ - (void)__showLeftMenuViewController [self.view.window endEditing:YES]; [self __addContentButton]; [self __updateContentViewShadow]; - - [UIView animateWithDuration:self.animationDuration animations:^{ + + 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; + NSLog(@"initalSpringVelocity: %f", initalSpringVelocity); + + [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 + CGRectGetHeight(self.view.frame) : self.contentViewInPortraitOffsetCenterX + CGRectGetWidth(self.view.frame)), self.contentViewContainer.center.y); + self.contentViewContainer.center = CGPointMake(targetContentViewContainerCenterX, self.contentViewContainer.center.y); self.menuViewContainer.alpha = 1.0f; self.menuViewContainer.transform = CGAffineTransformIdentity; @@ -278,7 +294,7 @@ - (void)__showLeftMenuViewController } completion:^(BOOL finished) { [self __addContentViewControllerMotionEffects]; - + if (!self.visible && [self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:didShowMenuViewController:)]) { [self.delegate sideMenu:self didShowMenuViewController:self.leftMenuViewController]; } @@ -286,11 +302,16 @@ - (void)__showLeftMenuViewController self.visible = YES; self.leftMenuVisible = YES; }]; - + [self __statusBarNeedsAppearanceUpdate]; } - (void)__showRightMenuViewController +{ + [self __showRightMenuViewControllerWithVelocity:0]; +} + +- (void)__showRightMenuViewControllerWithVelocity:(CGFloat)velocity { if (!self.rightMenuViewController) { return; @@ -300,15 +321,25 @@ - (void)__showRightMenuViewController [self.view.window endEditing:YES]; [self __addContentButton]; [self __updateContentViewShadow]; - + + 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 = 1.0f; self.menuViewContainer.transform = CGAffineTransformIdentity; @@ -337,6 +368,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:)]) { @@ -382,8 +418,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]; @@ -638,21 +683,22 @@ - (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]; + [self __showLeftMenuViewControllerWithVelocity:velocityX]; } } } else { if (self.contentViewContainer.frame.origin.x < 20) { if (self.rightMenuViewController) { - [self __showRightMenuViewController]; + [self __showRightMenuViewControllerWithVelocity:-velocityX]; } } else { - [self hideMenuViewController]; + [self __hideMenuViewControllerAnimated:YES withVelocity:-velocityX]; } } } From 11cbccf33ddc18eb1d697e4699c935c992d7c0ad Mon Sep 17 00:00:00 2001 From: David Hart Date: Wed, 6 Aug 2014 15:48:33 +0200 Subject: [PATCH 2/3] Added gitignore and remove log --- .gitignore | 3 +++ .../RESideMenuStoryboardsExample.xccheckout | 10 +++++----- RESideMenu/RESideMenu.m | 1 - 3 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 .gitignore 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/Examples/Storyboards/RESideMenuStoryboardsExample.xcodeproj/project.xcworkspace/xcshareddata/RESideMenuStoryboardsExample.xccheckout b/Examples/Storyboards/RESideMenuStoryboardsExample.xcodeproj/project.xcworkspace/xcshareddata/RESideMenuStoryboardsExample.xccheckout index c94eb4b4..6a4fafc2 100644 --- a/Examples/Storyboards/RESideMenuStoryboardsExample.xcodeproj/project.xcworkspace/xcshareddata/RESideMenuStoryboardsExample.xccheckout +++ b/Examples/Storyboards/RESideMenuStoryboardsExample.xcodeproj/project.xcworkspace/xcshareddata/RESideMenuStoryboardsExample.xccheckout @@ -10,29 +10,29 @@ RESideMenuStoryboardsExample IDESourceControlProjectOriginsDictionary - D8E9CD00-2368-4ABD-BD15-AB69D787B293 + 4D9AE519C7D7E765CA7498EFD8B3BB24ACB11215 ssh://github.com/romaonthego/RESideMenu.git IDESourceControlProjectPath Examples/Storyboards/RESideMenuStoryboardsExample.xcodeproj/project.xcworkspace IDESourceControlProjectRelativeInstallPathDictionary - D8E9CD00-2368-4ABD-BD15-AB69D787B293 + 4D9AE519C7D7E765CA7498EFD8B3BB24ACB11215 ../../../.. IDESourceControlProjectURL ssh://github.com/romaonthego/RESideMenu.git IDESourceControlProjectVersion - 110 + 111 IDESourceControlProjectWCCIdentifier - D8E9CD00-2368-4ABD-BD15-AB69D787B293 + 4D9AE519C7D7E765CA7498EFD8B3BB24ACB11215 IDESourceControlProjectWCConfigurations IDESourceControlRepositoryExtensionIdentifierKey public.vcs.git IDESourceControlWCCIdentifierKey - D8E9CD00-2368-4ABD-BD15-AB69D787B293 + 4D9AE519C7D7E765CA7498EFD8B3BB24ACB11215 IDESourceControlWCCName RESideMenu diff --git a/RESideMenu/RESideMenu.m b/RESideMenu/RESideMenu.m index 083fb825..c7719c73 100755 --- a/RESideMenu/RESideMenu.m +++ b/RESideMenu/RESideMenu.m @@ -272,7 +272,6 @@ - (void)__showLeftMenuViewControllerWithVelocity:(CGFloat)velocity 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; - NSLog(@"initalSpringVelocity: %f", initalSpringVelocity); [UIView animateWithDuration:self.animationDuration delay:0 From 10bbaf4a693eed8f7d0425dbeadb6a0218c447ec Mon Sep 17 00:00:00 2001 From: David Hart Date: Mon, 29 Sep 2014 13:38:59 +0200 Subject: [PATCH 3/3] Made visibility property readonly in header --- RESideMenu/RESideMenu.h | 4 ++++ RESideMenu/RESideMenu.m | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) 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 index ab6cebaf..9094414d 100755 --- 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;