Skip to content

Commit

Permalink
Allow the swipe direction to be overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
andygeers committed Feb 11, 2015
1 parent 47c593a commit b009795
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Coach Marks/DDCircleView.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@

#import <UIKit/UIKit.h>

enum EnumCircleSwipeDirection {
kCircleSwipeLeftToRight,
kCircleSwipeRightToLeft
};

@interface DDCircleView : UIView

@property BOOL animationShouldStop;
@property enum EnumCircleSwipeDirection swipeDirection;

- (void)swipeInFrame:(CGRect)frame;

Expand Down
32 changes: 25 additions & 7 deletions Coach Marks/DDCircleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
}];
}];

Expand Down
8 changes: 8 additions & 0 deletions Coach Marks/DDCoachMarksView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -230,6 +236,8 @@ - (void)showSwipeGesture
[self addSubview:self.animatingCircle];
}

self.animatingCircle.swipeDirection = direction;

[self.animatingCircle swipeInFrame:frame];
}
}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b009795

Please sign in to comment.