Skip to content

Commit

Permalink
Updated README and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamazz committed Apr 17, 2014
1 parent aba705d commit 6e687a6
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 16 deletions.
51 changes: 50 additions & 1 deletion AMWaveTransition/AMWaveTransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,59 @@ typedef NS_ENUM(NSInteger, AMWaveTransitionType) {

@interface AMWaveTransition : NSObject <UIViewControllerAnimatedTransitioning>

/**-----------------------------------------------------------------------------
* @name AMWaveTransition
* -----------------------------------------------------------------------------
*/

/** New transition
*
* Returns a AMWaveTransition instance.
*
* @param operation The UINavigationControllerOperation that determines the transition type (push or pop)
*/
+ (instancetype)transitionWithOperation:(UINavigationControllerOperation)operation;

/** New transition
*
* Returns a AMWaveTransition instance.
*
* @param operation The UINavigationControllerOperation that determines the transition type (push or pop)
*/
- (instancetype)initWithOperation:(UINavigationControllerOperation)operation;

@property (assign, nonatomic) AMWaveTransitionType transitionType UI_APPEARANCE_SELECTOR;

/**-----------------------------------------------------------------------------
* @name AMWaveTransition Properties
* -----------------------------------------------------------------------------
*/

/** Operation type
*
* Sets the operation type (push or pop)
*
*/
@property (assign, nonatomic) UINavigationControllerOperation operation;

/** Transition type
*
* Sets the transition style
*
*/
@property (assign, nonatomic) AMWaveTransitionType transitionType UI_APPEARANCE_SELECTOR;

/** Animation duration
*
* Sets the duration of the animation. The whole duration accounts for the maxDelay property.
*
*/
@property (assign, nonatomic) CGFloat duration UI_APPEARANCE_SELECTOR;

/** Maximum animation delay
*
* Sets the max delay that a cell will wait beofre animating.
*
*/
@property (assign, nonatomic) CGFloat maxDelay UI_APPEARANCE_SELECTOR;

@end
24 changes: 12 additions & 12 deletions AMWaveTransition/AMWaveTransition.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ - (instancetype)initWithOperation:(UINavigationControllerOperation)operation
self = [super init];
if (self) {
_operation = operation;
_duration = DURATION;
_maxDelay = MAX_DELAY;
_transitionType = AMWaveTransitionTypeNervous;
}
return self;
}

- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
{
return DURATION + MAX_DELAY;
return self.duration + self.maxDelay;
}

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

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

// Plain animation that moves the destination controller in place. Once it's done it will notify the transition context
if (self.operation == UINavigationControllerOperationPush) {
[toVC.view setTransform:CGAffineTransformMakeTranslation(1, 0)];
[UIView animateWithDuration:DURATION + MAX_DELAY delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
[UIView animateWithDuration:self.duration + self.maxDelay delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
[toVC.view setTransform:CGAffineTransformIdentity];
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
} else {
[fromVC.view setTransform:CGAffineTransformMakeTranslation(1, 0)];
[toVC.view setTransform:CGAffineTransformIdentity];
[UIView animateWithDuration:DURATION + MAX_DELAY delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
[UIView animateWithDuration:self.duration + self.maxDelay delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
[fromVC.view setTransform:CGAffineTransformMakeTranslation(SCREEN_WIDTH, 0)];
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
Expand All @@ -103,7 +103,7 @@ - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionC
// Animates the cells of the starting view controller
if ([fromVC respondsToSelector:@selector(visibleCells)]) {
[[fromVC visibleCells] enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UITableViewCell *obj, NSUInteger idx, BOOL *stop) {
NSTimeInterval delay = ((float)idx / (float)[[fromVC visibleCells] count]) * MAX_DELAY;
NSTimeInterval delay = ((float)idx / (float)[[fromVC visibleCells] count]) * self.maxDelay;
void (^animation)() = ^{
[obj setTransform:CGAffineTransformMakeTranslation(-delta, 0)];
[obj setAlpha:0];
Expand All @@ -112,25 +112,25 @@ - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionC
[obj setTransform:CGAffineTransformIdentity];
};
if (self.transitionType == AMWaveTransitionTypeSubtle) {
[UIView animateWithDuration:DURATION delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
} else {
[UIView animateWithDuration:DURATION delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
}
}];
}

if ([toVC respondsToSelector:@selector(visibleCells)]) {
[[toVC visibleCells] enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UITableViewCell *obj, NSUInteger idx, BOOL *stop) {
NSTimeInterval delay = ((float)idx / (float)[[fromVC visibleCells] count]) * MAX_DELAY;
NSTimeInterval delay = ((float)idx / (float)[[fromVC visibleCells] count]) * self.maxDelay;
[obj setTransform:CGAffineTransformMakeTranslation(delta, 0)];
void (^animation)() = ^{
[obj setTransform:CGAffineTransformIdentity];
[obj setAlpha:1];
};
if (self.transitionType == AMWaveTransitionTypeSubtle) {
[UIView animateWithDuration:DURATION delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
} else {
[UIView animateWithDuration:DURATION delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
}
}];
}
Expand Down
49 changes: 46 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,56 @@ Screenshot
Getting Started
=================

Setup
Install
--------------------
* Add ```pod 'AMWaveTransition'``` to your [Podfile](http://cocoapods.org/)
* Run ```pod install```
* Run ```open App.xcworkspace```
* Subclass ```AMWaveViewController``` or replicate its implementation in your view controllers

Setup as superclass
--------------------
* Subclass ```AMWaveViewController``` and override ```visibleCells``` or follow these steps:

Setup manually
--------------------
Implement ```UINavigationControllerDelegate``` and this delegate method:
```objc
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController*)fromVC
toViewController:(UIViewController*)toVC
{
if (operation != UINavigationControllerOperationNone) {
// Return your preferred transition operation
return [AMWaveTransition transitionWithOperation:operation];
}
return nil;
}
```
Remember to set your instance as the navigation delegate:
```objc
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.navigationController setDelegate:self];
}

- (void)dealloc
{
[self.navigationController setDelegate:nil];
}
```

Implement th ```AMWaveTransitioning``` protocol by returning your tableview's visible cells:
```objc
- (NSArray*)visibleCells
{
return [self.tableView visibleCells];
}
```

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.


Changelog
==================
Expand All @@ -30,7 +74,6 @@ Changelog

TODO
==================
* Parametrize animations values
* Improve documentation

MIT License
Expand Down

0 comments on commit 6e687a6

Please sign in to comment.