@@ -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
0 commit comments