Skip to content

Commit 5dfdd05

Browse files
committed
Integrated changes from voznesenskym/AMWaveTransition
1 parent 08e506c commit 5dfdd05

File tree

5 files changed

+54
-19
lines changed

5 files changed

+54
-19
lines changed

AMWaveTransition.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Pod::Spec.new do |s|
22
s.name = "AMWaveTransition"
3-
s.version = "0.4"
3+
s.version = "0.5"
44
s.summary = "Custom transition between viewcontrollers holding tableviews. Each cell is animated to simulate a 'wave effect'."
55
s.homepage = "https://github.com/andreamazz/AMWaveTransition"
66
s.license = { :type => 'MIT', :file => 'LICENSE' }
77
s.author = { "Andrea Mazzini" => "andrea.mazzini@gmail.com" }
8-
s.source = { :git => "https://github.com/andreamazz/AMWaveTransition.git", :tag => '0.4' }
8+
s.source = { :git => "https://github.com/andreamazz/AMWaveTransition.git", :tag => '0.5' }
99
s.platform = :ios, '7.0'
1010
s.source_files = 'AMWaveTransition', '*.{h,m}'
1111
s.requires_arc = true

AMWaveTransition/AMWaveTransition.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
typedef NS_ENUM(NSInteger, AMWaveTransitionType) {
1616
AMWaveTransitionTypeSubtle,
17-
AMWaveTransitionTypeNervous
17+
AMWaveTransitionTypeNervous,
18+
AMWaveTransitionTypeBounce
1819
};
1920

2021
@interface AMWaveTransition : NSObject <UIViewControllerAnimatedTransitioning>
@@ -32,6 +33,15 @@ typedef NS_ENUM(NSInteger, AMWaveTransitionType) {
3233
*/
3334
+ (instancetype)transitionWithOperation:(UINavigationControllerOperation)operation;
3435

36+
/** New transition
37+
*
38+
* Returns a AMWaveTransition instance.
39+
*
40+
* @param operation The UINavigationControllerOperation that determines the transition type (push or pop)
41+
* @param type The transition type
42+
*/
43+
+ (instancetype)transitionWithOperation:(UINavigationControllerOperation)operation andTransitionType:(AMWaveTransitionType)type;
44+
3545
/** New transition
3646
*
3747
* Returns a AMWaveTransition instance.
@@ -40,6 +50,15 @@ typedef NS_ENUM(NSInteger, AMWaveTransitionType) {
4050
*/
4151
- (instancetype)initWithOperation:(UINavigationControllerOperation)operation;
4252

53+
/** New transition
54+
*
55+
* Returns a AMWaveTransition instance.
56+
*
57+
* @param operation The UINavigationControllerOperation that determines the transition type (push or pop)
58+
* @param type The transition type
59+
*/
60+
- (instancetype)initWithOperation:(UINavigationControllerOperation)operation andTransitionType:(AMWaveTransitionType)type;
61+
4362
/** Attach the interactive gesture
4463
*
4564
* Attach the interactive gesture to the navigation controller. This will pop the current view controller when the user swipes from the left edge.

AMWaveTransition/AMWaveTransition.m

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,34 @@ - (instancetype)init
3333
self = [super init];
3434
if (self) {
3535
[self setup];
36+
_operation = UINavigationControllerOperationNone;
37+
_transitionType = AMWaveTransitionTypeNervous;
3638
}
3739
return self;
3840
}
3941

4042
+ (instancetype)transitionWithOperation:(UINavigationControllerOperation)operation
4143
{
42-
return [[self alloc] initWithOperation:operation];
44+
return [[self alloc] initWithOperation:operation andTransitionType:AMWaveTransitionTypeNervous];
4345
}
4446

4547
- (instancetype)initWithOperation:(UINavigationControllerOperation)operation
48+
{
49+
return [self initWithOperation:operation andTransitionType:AMWaveTransitionTypeNervous];
50+
}
51+
52+
+ (instancetype)transitionWithOperation:(UINavigationControllerOperation)operation andTransitionType:(AMWaveTransitionType)type
53+
{
54+
return [[self alloc] initWithOperation:operation andTransitionType:type];
55+
}
56+
57+
- (instancetype)initWithOperation:(UINavigationControllerOperation)operation andTransitionType:(AMWaveTransitionType)type
4658
{
4759
self = [super init];
4860
if (self) {
49-
_operation = operation;
5061
[self setup];
62+
_operation = operation;
63+
_transitionType = type;
5164
}
5265
return self;
5366
}
@@ -56,7 +69,6 @@ - (void)setup
5669
{
5770
_duration = DURATION;
5871
_maxDelay = MAX_DELAY;
59-
_transitionType = AMWaveTransitionTypeNervous;
6072
}
6173

6274
- (void)attachInteractiveGestureToNavigationController:(UINavigationController *)navigationController
@@ -85,7 +97,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture
8597
// Starting controller
8698
UIViewController<AMWaveTransitioning> *fromVC;
8799
fromVC = (UIViewController<AMWaveTransitioning> *)self.navigationController.topViewController;
88-
100+
89101
// Controller that will be visible after the pop
90102
UIViewController<AMWaveTransitioning> *toVC;
91103
int index = (int)[self.navigationController.viewControllers indexOfObject:self.navigationController.topViewController];
@@ -94,7 +106,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture
94106
// The gesture velocity will also determine the velocity of the cells
95107
float velocity = [gesture velocityInView:self.navigationController.view].x;
96108
CGPoint touch = [gesture locationInView:self.navigationController.view];
97-
109+
98110
if (gesture.state == UIGestureRecognizerStateBegan) {
99111
[[fromVC visibleCells] enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) {
100112
// The 'selected' cell will be the one leading the other cells
@@ -109,7 +121,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture
109121
[self.attachmentsFrom addObject:attachment];
110122
}];
111123

112-
124+
113125
// Kick the 'new' cells outside the view
114126
[[toVC visibleCells] enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) {
115127
CGRect rect = view.frame;
@@ -132,7 +144,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture
132144
[self.animator addBehavior:attachment];
133145
[self.attachmentsTo addObject:attachment];
134146
}];
135-
147+
136148
} else if (gesture.state == UIGestureRecognizerStateChanged) {
137149

138150
[[fromVC visibleCells] enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) {
@@ -143,7 +155,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture
143155
}
144156
[self.attachmentsFrom[idx] setAnchorPoint:(CGPoint){delta, [view.superview convertPoint:view.frame.origin toView:nil].y + view.frame.size.height / 2}];
145157
}];
146-
158+
147159
[[toVC visibleCells] enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) {
148160
float delta = [gesture locationInView:self.navigationController.view].x - abs(self.selectionIndexTo - (int)idx) * velocity / 50;
149161
// Prevent the anchor point from going 'over' the cell
@@ -158,7 +170,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture
158170
[self.animator removeBehavior:obj];
159171
}];
160172
[self.attachmentsFrom removeAllObjects];
161-
173+
162174
[self.attachmentsTo enumerateObjectsUsingBlock:^(UIAttachmentBehavior *obj, NSUInteger idx, BOOL *stop) {
163175
[self.animator removeBehavior:obj];
164176
}];
@@ -202,7 +214,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture
202214
}];
203215
[toVC.view removeFromSuperview];
204216
}];
205-
217+
206218
}
207219
}
208220
}
@@ -235,7 +247,7 @@ - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionC
235247
if (self.operation == UINavigationControllerOperationPush) {
236248
delta = SCREEN_WIDTH;
237249
} else {
238-
250+
239251
delta = -SCREEN_WIDTH;
240252
}
241253

@@ -276,7 +288,7 @@ - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionC
276288
// The controller has no table view, let's animate it gracefully
277289
[self hideView:fromVC.view withDelay:0 andDelta:-delta];
278290
}
279-
291+
280292
if ([toVC respondsToSelector:@selector(visibleCells)]) {
281293
[[toVC visibleCells] enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UITableViewCell *obj, NSUInteger idx, BOOL *stop) {
282294
NSTimeInterval delay = ((float)idx / (float)[[toVC visibleCells] count]) * self.maxDelay;
@@ -299,8 +311,10 @@ - (void)hideView:(UIView *)view withDelay:(NSTimeInterval)delay andDelta:(float)
299311
};
300312
if (self.transitionType == AMWaveTransitionTypeSubtle) {
301313
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
302-
} else {
314+
} else if (self.transitionType == AMWaveTransitionTypeNervous) {
303315
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
316+
} else if (self.transitionType == AMWaveTransitionTypeBounce){
317+
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseInOut animations:animation completion:completion];
304318
}
305319
}
306320

@@ -313,8 +327,10 @@ - (void)presentView:(UIView *)view withDelay:(NSTimeInterval)delay andDelta:(flo
313327
};
314328
if (self.transitionType == AMWaveTransitionTypeSubtle) {
315329
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
316-
} else {
330+
} else if (self.transitionType == AMWaveTransitionTypeNervous) {
317331
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
332+
} else if (self.transitionType == AMWaveTransitionTypeBounce){
333+
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseInOut animations:animation completion:nil];
318334
}
319335
}
320336

AMWaveTransition/AMWaveViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ - (void)viewDidDisappear:(BOOL)animated
4141
toViewController:(UIViewController*)toVC
4242
{
4343
if (operation != UINavigationControllerOperationNone) {
44-
return [AMWaveTransition transitionWithOperation:operation];
44+
return [AMWaveTransition transitionWithOperation:operation andTransitionType:AMWaveTransitionTypeNervous];
4545
}
4646
return nil;
4747
}

Demo/Demo/ViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS
7070
toViewController:(UIViewController*)toVC
7171
{
7272
if (operation != UINavigationControllerOperationNone) {
73-
return [AMWaveTransition transitionWithOperation:operation];
73+
return [AMWaveTransition transitionWithOperation:operation andTransitionType:AMWaveTransitionTypeBounce];
7474
}
7575
return nil;
7676
}

0 commit comments

Comments
 (0)