-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support smoother completion animation for panning velocity #18
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ | |
|
||
CGFloat const MMDrawerBezelRange = 20.0f; | ||
|
||
CGFloat const MMDrawerPanVelocityXAnimationThreshold = 100.0f; | ||
CGFloat const MMDrawerPanVelocityXAnimationThreshold = 200.0f; | ||
|
||
/** The amount of overshoot that is panned linearly. The remaining percentage nonlinearly asymptotes to the max percentage. */ | ||
CGFloat const MMDrawerOvershootLinearRangePercentage = 0.75f; | ||
|
@@ -181,10 +181,14 @@ -(void)toggleDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated complet | |
} | ||
|
||
-(void)closeDrawerAnimated:(BOOL)animated completion:(void (^)(BOOL))completion{ | ||
[self closeDrawerAnimated:animated velocity:self.animationVelocity animationOptions:UIViewAnimationOptionCurveEaseInOut completion:completion]; | ||
} | ||
|
||
-(void)closeDrawerAnimated:(BOOL)animated velocity:(CGFloat)velocity animationOptions:(UIViewAnimationOptions)options completion:(void (^)(BOOL))completion{ | ||
CGRect newFrame = self.view.bounds; | ||
|
||
CGFloat distance = ABS(CGRectGetMinX(self.centerContainerView.frame)); | ||
NSTimeInterval duration = [self animationDurationForAnimationDistance:distance]; | ||
NSTimeInterval duration = MAX(distance/ABS(velocity),MMDrawerMinimumAnimationDuration); | ||
|
||
BOOL leftDrawerVisible = CGRectGetMinX(self.centerContainerView.frame) > 0; | ||
BOOL rightDrawerVisible = CGRectGetMinX(self.centerContainerView.frame) < 0; | ||
|
@@ -212,14 +216,14 @@ -(void)closeDrawerAnimated:(BOOL)animated completion:(void (^)(BOOL))completion{ | |
[UIView | ||
animateWithDuration:(animated?duration:0.0) | ||
delay:0.0 | ||
options:UIViewAnimationOptionCurveEaseInOut | ||
options:options | ||
animations:^{ | ||
[self.centerContainerView setFrame:newFrame]; | ||
[self updateDrawerVisualStateForDrawerSide:visibleSide percentVisible:0.0]; | ||
} | ||
completion:^(BOOL finished) { | ||
[sideDrawerViewController endAppearanceTransition]; | ||
[self setOpenSide:MMDrawerSideNone]; | ||
[self setOpenSide:MMDrawerSideNone]; | ||
[self resetDrawerVisualStateForDrawerSide:visibleSide]; | ||
|
||
if(completion){ | ||
|
@@ -231,6 +235,12 @@ -(void)closeDrawerAnimated:(BOOL)animated completion:(void (^)(BOOL))completion{ | |
-(void)openDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated completion:(void (^)(BOOL))completion{ | ||
NSParameterAssert(drawerSide != MMDrawerSideNone); | ||
|
||
[self openDrawerSide:drawerSide animated:animated velocity:self.animationVelocity animationOptions:UIViewAnimationOptionCurveEaseInOut completion:completion]; | ||
} | ||
|
||
-(void)openDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated velocity:(CGFloat)velocity animationOptions:(UIViewAnimationOptions)options completion:(void (^)(BOOL))completion{ | ||
NSParameterAssert(drawerSide != MMDrawerSideNone); | ||
|
||
UIViewController * sideDrawerViewController = [self sideDrawerViewControllerForSide:drawerSide]; | ||
CGRect visibleRect = CGRectIntersection(self.view.bounds,sideDrawerViewController.view.frame); | ||
BOOL drawerFullyCovered = (CGRectContainsRect(self.centerContainerView.frame, visibleRect) || | ||
|
@@ -252,12 +262,12 @@ -(void)openDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated completio | |
} | ||
|
||
CGFloat distance = ABS(CGRectGetMinX(oldFrame)-newFrame.origin.x); | ||
NSTimeInterval duration = [self animationDurationForAnimationDistance:distance]; | ||
NSTimeInterval duration = MAX(distance/ABS(velocity),MMDrawerMinimumAnimationDuration); | ||
|
||
[UIView | ||
animateWithDuration:(animated?duration:0.0) | ||
delay:0.0 | ||
options:UIViewAnimationOptionCurveEaseInOut | ||
options:options | ||
animations:^{ | ||
[self.centerContainerView setFrame:newFrame]; | ||
[self updateDrawerVisualStateForDrawerSide:drawerSide percentVisible:1.0]; | ||
|
@@ -792,10 +802,10 @@ -(void)finishAnimationForPanGestureWithXVelocity:(CGFloat)xVelocity completion:( | |
if(self.openSide == MMDrawerSideLeft) { | ||
CGFloat midPoint = self.maximumLeftDrawerWidth / 2.0; | ||
if(xVelocity > MMDrawerPanVelocityXAnimationThreshold){ | ||
[self openDrawerSide:MMDrawerSideLeft animated:YES completion:completion]; | ||
[self openDrawerSide:MMDrawerSideLeft animated:YES velocity:MAX(ABS(xVelocity),MMDrawerPanVelocityXAnimationThreshold*2) animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion]; | ||
} | ||
else if(xVelocity < -MMDrawerPanVelocityXAnimationThreshold){ | ||
[self closeDrawerAnimated:YES completion:completion]; | ||
[self closeDrawerAnimated:YES velocity:MAX(ABS(xVelocity),MMDrawerPanVelocityXAnimationThreshold*2) animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion]; | ||
} | ||
else if(currentOriginX < midPoint){ | ||
[self closeDrawerAnimated:YES completion:completion]; | ||
|
@@ -808,10 +818,10 @@ -(void)finishAnimationForPanGestureWithXVelocity:(CGFloat)xVelocity completion:( | |
currentOriginX = CGRectGetMaxX(self.centerContainerView.frame); | ||
CGFloat midPoint = (CGRectGetWidth(self.view.bounds)-self.maximumRightDrawerWidth) + (self.maximumRightDrawerWidth / 2.0); | ||
if(xVelocity > MMDrawerPanVelocityXAnimationThreshold){ | ||
[self closeDrawerAnimated:YES completion:completion]; | ||
[self closeDrawerAnimated:YES velocity:MAX(ABS(xVelocity),MMDrawerPanVelocityXAnimationThreshold*2) animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with this calculated velocity here |
||
} | ||
else if (xVelocity < -MMDrawerPanVelocityXAnimationThreshold){ | ||
[self openDrawerSide:MMDrawerSideRight animated:YES completion:completion]; | ||
[self openDrawerSide:MMDrawerSideRight animated:YES velocity:MAX(ABS(xVelocity),MMDrawerPanVelocityXAnimationThreshold*2) animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion]; | ||
} | ||
else if(currentOriginX > midPoint){ | ||
[self closeDrawerAnimated:YES completion:completion]; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The velocity passed in here is the same in both places. Just break it out into a new
animationVelocity
variable and use that in both places.