From b0097950e675fd01e3d2da8bbafd5d011ca1d7f2 Mon Sep 17 00:00:00 2001 From: Andy Geers Date: Wed, 11 Feb 2015 11:48:55 +0000 Subject: [PATCH] Allow the swipe direction to be overridden --- Coach Marks/DDCircleView.h | 6 ++++++ Coach Marks/DDCircleView.m | 32 +++++++++++++++++++++++++------- Coach Marks/DDCoachMarksView.m | 8 ++++++++ README.md | 2 ++ 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Coach Marks/DDCircleView.h b/Coach Marks/DDCircleView.h index 4d2c3a8..8a961fc 100644 --- a/Coach Marks/DDCircleView.h +++ b/Coach Marks/DDCircleView.h @@ -8,9 +8,15 @@ #import +enum EnumCircleSwipeDirection { + kCircleSwipeLeftToRight, + kCircleSwipeRightToLeft +}; + @interface DDCircleView : UIView @property BOOL animationShouldStop; +@property enum EnumCircleSwipeDirection swipeDirection; - (void)swipeInFrame:(CGRect)frame; diff --git a/Coach Marks/DDCircleView.m b/Coach Marks/DDCircleView.m index a711e85..b0de0e5 100644 --- a/Coach Marks/DDCircleView.m +++ b/Coach Marks/DDCircleView.m @@ -39,32 +39,50 @@ - (void)userTap:(UITapGestureRecognizer *)recognizer { - (void)swipeInFrame:(CGRect)frame { [self centerYPositioninView:self inFrame:frame]; - [self animateSwipeRight]; + [self animateSwipe]; } -- (void)animateSwipeRight +- (void)animateSwipe { if (!_animationShouldStop) { - self.transform = CGAffineTransformMakeScale(2, 2); + CGAffineTransform scale = CGAffineTransformMakeScale(2, 2); + CGAffineTransform translateRight = CGAffineTransformMakeTranslation(260, 0); + if (self.swipeDirection == kCircleSwipeLeftToRight) { + self.transform = scale; + } else { + // Start on the right hand side as well as scaling + self.transform = CGAffineTransformConcat(translateRight, scale); + } self.alpha = 0.0f; [UIView animateKeyframesWithDuration:0.6 delay:0.3 options:0 animations:^{ // Fade In - self.transform = CGAffineTransformMakeScale(1, 1); + if (self.swipeDirection == kCircleSwipeLeftToRight) { + // Scale down to normal + self.transform = CGAffineTransformMakeScale(1, 1); + } else { + // Start on the right hand side + self.transform = translateRight; + } self.alpha = 1.0f; } completion:^(BOOL finished){ // End [UIView animateWithDuration:1.0 animations:^{ - // Slide Right - self.transform = CGAffineTransformMakeTranslation(260, 0); + if (self.swipeDirection == kCircleSwipeLeftToRight) { + // Slide Right + self.transform = translateRight; + } else { + // Slide left + self.transform = CGAffineTransformIdentity; + } // Fade Out self.alpha = 0.0f; } completion:^(BOOL finished) { // End - [self performSelector:@selector(animateSwipeRight)]; + [self performSelector:@selector(animateSwipe)]; }]; }]; diff --git a/Coach Marks/DDCoachMarksView.m b/Coach Marks/DDCoachMarksView.m index 43b9b46..e67ecd8 100755 --- a/Coach Marks/DDCoachMarksView.m +++ b/Coach Marks/DDCoachMarksView.m @@ -212,6 +212,12 @@ - (void)showSwipeGesture CGRect frame = [[coachMarkInfo objectForKey:@"rect"] CGRectValue]; BOOL shouldAnimateSwipe = [[coachMarkInfo objectForKey:@"swipe"] boolValue]; + NSString* swipeDirection = [coachMarkInfo objectForKey:@"direction"]; + enum EnumCircleSwipeDirection direction = kCircleSwipeLeftToRight; + if ((swipeDirection != nil) && ([swipeDirection isEqualToString:@"righttoleft"])) { + direction = kCircleSwipeRightToLeft; + } + // if next animation doesn't need swipe // remove current swiping circle if one exists if (self.animatingCircle) { @@ -230,6 +236,8 @@ - (void)showSwipeGesture [self addSubview:self.animatingCircle]; } + self.animatingCircle.swipeDirection = direction; + [self.animatingCircle swipeInFrame:frame]; } } diff --git a/README.md b/README.md index 92c7c28..a642cbc 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,8 @@ Text that goes in the bubbles Stands for 'point of interest'. You can define a whole region using the `@"rect"` value, but defining a different CGRect value here makes the bubble caption position itself under the POI rect. * `@"swipe"` Use "YES" here if you want to show a row swipe gesture on a table view cell. Disabled by default. +* `@"direction"` + Direction that swipe gestures should animate in. The default is `@"lefttoright"` but you can also specify `@"righttoleft"`. ## DDCoachMarksViewDelegate