Skip to content

Commit 6e687a6

Browse files
committed
Updated README and documentation
1 parent aba705d commit 6e687a6

File tree

3 files changed

+108
-16
lines changed

3 files changed

+108
-16
lines changed

AMWaveTransition/AMWaveTransition.h

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,59 @@ typedef NS_ENUM(NSInteger, AMWaveTransitionType) {
1919

2020
@interface AMWaveTransition : NSObject <UIViewControllerAnimatedTransitioning>
2121

22+
/**-----------------------------------------------------------------------------
23+
* @name AMWaveTransition
24+
* -----------------------------------------------------------------------------
25+
*/
26+
27+
/** New transition
28+
*
29+
* Returns a AMWaveTransition instance.
30+
*
31+
* @param operation The UINavigationControllerOperation that determines the transition type (push or pop)
32+
*/
2233
+ (instancetype)transitionWithOperation:(UINavigationControllerOperation)operation;
34+
35+
/** New transition
36+
*
37+
* Returns a AMWaveTransition instance.
38+
*
39+
* @param operation The UINavigationControllerOperation that determines the transition type (push or pop)
40+
*/
2341
- (instancetype)initWithOperation:(UINavigationControllerOperation)operation;
2442

25-
@property (assign, nonatomic) AMWaveTransitionType transitionType UI_APPEARANCE_SELECTOR;
43+
44+
/**-----------------------------------------------------------------------------
45+
* @name AMWaveTransition Properties
46+
* -----------------------------------------------------------------------------
47+
*/
48+
49+
/** Operation type
50+
*
51+
* Sets the operation type (push or pop)
52+
*
53+
*/
2654
@property (assign, nonatomic) UINavigationControllerOperation operation;
2755

56+
/** Transition type
57+
*
58+
* Sets the transition style
59+
*
60+
*/
61+
@property (assign, nonatomic) AMWaveTransitionType transitionType UI_APPEARANCE_SELECTOR;
62+
63+
/** Animation duration
64+
*
65+
* Sets the duration of the animation. The whole duration accounts for the maxDelay property.
66+
*
67+
*/
68+
@property (assign, nonatomic) CGFloat duration UI_APPEARANCE_SELECTOR;
69+
70+
/** Maximum animation delay
71+
*
72+
* Sets the max delay that a cell will wait beofre animating.
73+
*
74+
*/
75+
@property (assign, nonatomic) CGFloat maxDelay UI_APPEARANCE_SELECTOR;
76+
2877
@end

AMWaveTransition/AMWaveTransition.m

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ - (instancetype)initWithOperation:(UINavigationControllerOperation)operation
3434
self = [super init];
3535
if (self) {
3636
_operation = operation;
37+
_duration = DURATION;
38+
_maxDelay = MAX_DELAY;
3739
_transitionType = AMWaveTransitionTypeNervous;
3840
}
3941
return self;
4042
}
4143

4244
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
4345
{
44-
return DURATION + MAX_DELAY;
46+
return self.duration + self.maxDelay;
4547
}
4648

4749
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
@@ -77,22 +79,20 @@ - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionC
7779
toVC.view.transform = CGAffineTransformMakeTranslation(SCREEN_WIDTH, 0);
7880

7981
// First step is required to trigger the load of the visible cells.
80-
[UIView animateWithDuration:0 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
81-
// toVC.view.transform = CGAffineTransformMakeTranslation(SCREEN_WIDTH, 0);
82-
} completion:^(BOOL finished) {
82+
[UIView animateWithDuration:0 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:nil completion:^(BOOL finished) {
8383

8484
// Plain animation that moves the destination controller in place. Once it's done it will notify the transition context
8585
if (self.operation == UINavigationControllerOperationPush) {
8686
[toVC.view setTransform:CGAffineTransformMakeTranslation(1, 0)];
87-
[UIView animateWithDuration:DURATION + MAX_DELAY delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
87+
[UIView animateWithDuration:self.duration + self.maxDelay delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
8888
[toVC.view setTransform:CGAffineTransformIdentity];
8989
} completion:^(BOOL finished) {
9090
[transitionContext completeTransition:YES];
9191
}];
9292
} else {
9393
[fromVC.view setTransform:CGAffineTransformMakeTranslation(1, 0)];
9494
[toVC.view setTransform:CGAffineTransformIdentity];
95-
[UIView animateWithDuration:DURATION + MAX_DELAY delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
95+
[UIView animateWithDuration:self.duration + self.maxDelay delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
9696
[fromVC.view setTransform:CGAffineTransformMakeTranslation(SCREEN_WIDTH, 0)];
9797
} completion:^(BOOL finished) {
9898
[transitionContext completeTransition:YES];
@@ -103,7 +103,7 @@ - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionC
103103
// Animates the cells of the starting view controller
104104
if ([fromVC respondsToSelector:@selector(visibleCells)]) {
105105
[[fromVC visibleCells] enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UITableViewCell *obj, NSUInteger idx, BOOL *stop) {
106-
NSTimeInterval delay = ((float)idx / (float)[[fromVC visibleCells] count]) * MAX_DELAY;
106+
NSTimeInterval delay = ((float)idx / (float)[[fromVC visibleCells] count]) * self.maxDelay;
107107
void (^animation)() = ^{
108108
[obj setTransform:CGAffineTransformMakeTranslation(-delta, 0)];
109109
[obj setAlpha:0];
@@ -112,25 +112,25 @@ - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionC
112112
[obj setTransform:CGAffineTransformIdentity];
113113
};
114114
if (self.transitionType == AMWaveTransitionTypeSubtle) {
115-
[UIView animateWithDuration:DURATION delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
115+
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
116116
} else {
117-
[UIView animateWithDuration:DURATION delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
117+
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
118118
}
119119
}];
120120
}
121121

122122
if ([toVC respondsToSelector:@selector(visibleCells)]) {
123123
[[toVC visibleCells] enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UITableViewCell *obj, NSUInteger idx, BOOL *stop) {
124-
NSTimeInterval delay = ((float)idx / (float)[[fromVC visibleCells] count]) * MAX_DELAY;
124+
NSTimeInterval delay = ((float)idx / (float)[[fromVC visibleCells] count]) * self.maxDelay;
125125
[obj setTransform:CGAffineTransformMakeTranslation(delta, 0)];
126126
void (^animation)() = ^{
127127
[obj setTransform:CGAffineTransformIdentity];
128128
[obj setAlpha:1];
129129
};
130130
if (self.transitionType == AMWaveTransitionTypeSubtle) {
131-
[UIView animateWithDuration:DURATION delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
131+
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
132132
} else {
133-
[UIView animateWithDuration:DURATION delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
133+
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
134134
}
135135
}];
136136
}

README.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,56 @@ Screenshot
1414
Getting Started
1515
=================
1616

17-
Setup
17+
Install
1818
--------------------
1919
* Add ```pod 'AMWaveTransition'``` to your [Podfile](http://cocoapods.org/)
2020
* Run ```pod install```
2121
* Run ```open App.xcworkspace```
22-
* Subclass ```AMWaveViewController``` or replicate its implementation in your view controllers
22+
23+
Setup as superclass
24+
--------------------
25+
* Subclass ```AMWaveViewController``` and override ```visibleCells``` or follow these steps:
26+
27+
Setup manually
28+
--------------------
29+
Implement ```UINavigationControllerDelegate``` and this delegate method:
30+
```objc
31+
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
32+
animationControllerForOperation:(UINavigationControllerOperation)operation
33+
fromViewController:(UIViewController*)fromVC
34+
toViewController:(UIViewController*)toVC
35+
{
36+
if (operation != UINavigationControllerOperationNone) {
37+
// Return your preferred transition operation
38+
return [AMWaveTransition transitionWithOperation:operation];
39+
}
40+
return nil;
41+
}
42+
```
43+
Remember to set your instance as the navigation delegate:
44+
```objc
45+
- (void)viewDidAppear:(BOOL)animated
46+
{
47+
[super viewDidAppear:animated];
48+
[self.navigationController setDelegate:self];
49+
}
50+
51+
- (void)dealloc
52+
{
53+
[self.navigationController setDelegate:nil];
54+
}
55+
```
56+
57+
Implement th ```AMWaveTransitioning``` protocol by returning your tableview's visible cells:
58+
```objc
59+
- (NSArray*)visibleCells
60+
{
61+
return [self.tableView visibleCells];
62+
}
63+
```
64+
65+
As you can see in the sample project, the best results are obtained by setting the view and the cells' background to ```clearColor```, and setting a background color or a background image to the navigation controller.
66+
2367

2468
Changelog
2569
==================
@@ -30,7 +74,6 @@ Changelog
3074

3175
TODO
3276
==================
33-
* Parametrize animations values
3477
* Improve documentation
3578

3679
MIT License

0 commit comments

Comments
 (0)