diff --git a/Source/AMWaveTransition.h b/Source/AMWaveTransition.h index 82f2e14..f65c745 100644 --- a/Source/AMWaveTransition.h +++ b/Source/AMWaveTransition.h @@ -8,9 +8,9 @@ @import UIKit; -/**----------------------------------------------------------------------------- +/** * @name AMWaveTransitioning - * ----------------------------------------------------------------------------- + * Delegate protocol for AMWaveTransition */ @protocol AMWaveTransitioning @@ -29,8 +29,11 @@ * Enum that specifies the type of animation */ typedef NS_ENUM(NSInteger, AMWaveTransitionType) { + /** Smooth transition */ AMWaveTransitionTypeSubtle, + /** Springy transition */ AMWaveTransitionTypeNervous, + /** Spring transition with looser springs */ AMWaveTransitionTypeBounce }; @@ -39,16 +42,17 @@ typedef NS_ENUM(NSInteger, AMWaveTransitionType) { * Enum that specifies the transition type */ typedef NS_ENUM(NSInteger, AMWaveInteractiveTransitionType) { + /** The transition needs to start from the edge */ AMWaveTransitionEdgePan, - AMWaveTransitionFullScreenPan, + /** The transition can start from anywhere */ + AMWaveTransitionFullScreenPan }; -@interface AMWaveTransition : NSObject - -/**----------------------------------------------------------------------------- +/** * @name AMWaveTransition - * ----------------------------------------------------------------------------- + * Custom transition between viewcontrollers holding tableviews. Each cell is animated to simulate a 'wave effect'. */ +@interface AMWaveTransition : NSObject /** New transition * @@ -99,9 +103,8 @@ typedef NS_ENUM(NSInteger, AMWaveInteractiveTransitionType) { */ - (void)detachInteractiveGesture; -/**----------------------------------------------------------------------------- +/** * @name AMWaveTransition Properties - * ----------------------------------------------------------------------------- */ /** Operation type diff --git a/Source/AMWaveTransition.m b/Source/AMWaveTransition.m index 73f702f..ce0e12b 100644 --- a/Source/AMWaveTransition.m +++ b/Source/AMWaveTransition.m @@ -3,7 +3,7 @@ // AMWaveTransitioning // // Created by Andrea on 11/04/14. -// Copyright (c) 2014 Fancy Pixel. All rights reserved. +// Copyright (c) 2015 Fancy Pixel. All rights reserved. // #import "AMWaveTransition.h" @@ -53,23 +53,19 @@ - (instancetype)init { return self; } -+ (instancetype)transitionWithOperation:(UINavigationControllerOperation)operation -{ ++ (instancetype)transitionWithOperation:(UINavigationControllerOperation)operation { return [[self alloc] initWithOperation:operation andTransitionType:AMWaveTransitionTypeNervous]; } -- (instancetype)initWithOperation:(UINavigationControllerOperation)operation -{ +- (instancetype)initWithOperation:(UINavigationControllerOperation)operation { return [self initWithOperation:operation andTransitionType:AMWaveTransitionTypeNervous]; } -+ (instancetype)transitionWithOperation:(UINavigationControllerOperation)operation andTransitionType:(AMWaveTransitionType)type -{ ++ (instancetype)transitionWithOperation:(UINavigationControllerOperation)operation andTransitionType:(AMWaveTransitionType)type { return [[self alloc] initWithOperation:operation andTransitionType:type]; } -- (instancetype)initWithOperation:(UINavigationControllerOperation)operation andTransitionType:(AMWaveTransitionType)type -{ +- (instancetype)initWithOperation:(UINavigationControllerOperation)operation andTransitionType:(AMWaveTransitionType)type { self = [super init]; if (self) { [self setup]; @@ -79,8 +75,7 @@ - (instancetype)initWithOperation:(UINavigationControllerOperation)operation and return self; } -- (void)setup -{ +- (void)setup { _viewControllersInset = 20; _interactiveTransitionType = AMWaveTransitionEdgePan; _animateAlphaWithInteractiveTransition = NO; @@ -88,8 +83,7 @@ - (void)setup _maxDelay = MAX_DELAY; } -- (void)attachInteractiveGestureToNavigationController:(UINavigationController *)navigationController -{ +- (void)attachInteractiveGestureToNavigationController:(UINavigationController *)navigationController { self.navigationController = navigationController; if (self.interactiveTransitionType == AMWaveTransitionEdgePan) { UIScreenEdgePanGestureRecognizer *recognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self @@ -107,8 +101,7 @@ - (void)attachInteractiveGestureToNavigationController:(UINavigationController * self.attachmentsTo = [@[] mutableCopy]; } -- (void)detachInteractiveGesture -{ +- (void)detachInteractiveGesture { UINavigationController *navigationController = self.navigationController; [navigationController.view removeGestureRecognizer:self.gesture]; self.navigationController = nil; @@ -117,8 +110,7 @@ - (void)detachInteractiveGesture self.animator = nil; } -- (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture -{ +- (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture { UINavigationController *navigationController = self.navigationController; // support CLANG_WARN_OBJC_RECEIVER_WEAK // Starting controller @@ -239,8 +231,7 @@ - (void)handlePan:(UIScreenEdgePanGestureRecognizer *)gesture } } -- (void)animationCompletionForInteractiveTransitionForView:(UIView *)view -{ +- (void)animationCompletionForInteractiveTransitionForView:(UIView *)view { CGRect rect = view.frame; rect.origin.x = 0; UINavigationController *navigationController = self.navigationController; @@ -253,17 +244,14 @@ - (void)animationCompletionForInteractiveTransitionForView:(UIView *)view view.alpha = [self alphaForView:view]; } - -- (void)setPresentedFrameForView:(UIView *)view -{ +- (void)setPresentedFrameForView:(UIView *)view { CGRect rect = view.frame; rect.origin.x = 0; view.frame = rect; view.alpha = [self alphaForView:view]; } -- (void)kickCellOutside:(UIView *)view -{ +- (void)kickCellOutside:(UIView *)view { CGRect rect = view.frame; rect.origin.x = -SCREEN_WIDTH - self.viewControllersInset; UINavigationController *navigationController = self.navigationController; @@ -276,18 +264,15 @@ - (void)kickCellOutside:(UIView *)view view.frame = rect; } -- (void)completeToVC:(UIView *)view -{ +- (void)completeToVC:(UIView *)view { [self completeTransitionWithView:view inVC:AMWaveTransitionToVC]; } -- (void)completeFromVC:(UIView *)view -{ +- (void)completeFromVC:(UIView *)view { [self completeTransitionWithView:view inVC:AMWaveTransitionFromVC]; } -- (void)completeTransitionWithView:(UIView *)view inVC:(AMWaveTransitionViewControllers)viewController -{ +- (void)completeTransitionWithView:(UIView *)view inVC:(AMWaveTransitionViewControllers)viewController { CGRect rect = view.frame; if (viewController == AMWaveTransitionFromVC) { rect.origin.x = SCREEN_WIDTH - self.viewControllersInset; @@ -302,8 +287,7 @@ - (void)changeAttachmentWithIndex:(NSUInteger)index inView:(UIView *)view touchX:(CGFloat)touchX velocity:(CGFloat)velocity - inVC:(AMWaveTransitionViewControllers)viewController -{ + inVC:(AMWaveTransitionViewControllers)viewController { int selectionIndex; NSInteger correction = 2; NSMutableArray *arrayWithAttachments; @@ -328,8 +312,7 @@ - (void)changeAttachmentWithIndex:(NSUInteger)index [arrayWithAttachments[index] setAnchorPoint:(CGPoint){delta, [view.superview convertPoint:view.frame.origin toView:nil].y + view.frame.size.height / 2}]; } -- (void)createAttachmentForView:(UIView *)view inVC:(AMWaveTransitionViewControllers)viewController -{ +- (void)createAttachmentForView:(UIView *)view inVC:(AMWaveTransitionViewControllers)viewController { UIAttachmentBehavior *attachment = [[UIAttachmentBehavior alloc] initWithItem:view attachedToAnchor:(CGPoint){0, [view.superview convertPoint:view.frame.origin toView:nil].y + view.frame.size.height / 2}]; [attachment setDamping:0.4]; [attachment setFrequency:1]; @@ -346,8 +329,7 @@ - (void)createAttachmentForView:(UIView *)view inVC:(AMWaveTransitionViewControl [arrayWithAttachments addObject:attachment]; } -- (CGFloat)alphaForView:(UIView *)view -{ +- (CGFloat)alphaForView:(UIView *)view { if (self.animateAlphaWithInteractiveTransition) { CGFloat width = SCREEN_WIDTH - self.viewControllersInset; CGFloat alpha = (width - fabs(view.frame.origin.x)) * (1 / width); @@ -359,13 +341,11 @@ - (CGFloat)alphaForView:(UIView *)view #pragma mark - Non interactive transition -- (NSTimeInterval)transitionDuration:(id )transitionContext -{ +- (NSTimeInterval)transitionDuration:(id )transitionContext { return self.duration + self.maxDelay; } -- (void)animateTransition:(id )transitionContext -{ +- (void)animateTransition:(id )transitionContext { UIViewController *fromVC; if ([[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey] isKindOfClass:[UINavigationController class]]) { fromVC = (UIViewController*)([(UINavigationController*)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey] visibleViewController]); @@ -465,8 +445,7 @@ - (void)animateTransition:(id )transitionC }]; } -- (NSArray *)visibleCellsForViewController:(UIViewController*)viewController -{ +- (NSArray *)visibleCellsForViewController:(UIViewController*)viewController { NSArray *visibleCells = nil; if ([viewController respondsToSelector:@selector(visibleCells)]) { diff --git a/Source/AMWaveViewController.h b/Source/AMWaveViewController.h index fed6aa1..a640e0d 100644 --- a/Source/AMWaveViewController.h +++ b/Source/AMWaveViewController.h @@ -8,14 +8,13 @@ #import "AMWaveTransition.h" -@import UIKit; +#import -@interface AMWaveViewController : UIViewController - -/**----------------------------------------------------------------------------- +/** * @name AMWaveViewController - * ----------------------------------------------------------------------------- + * UIViewController subclass that implements the custom transition */ +@interface AMWaveViewController : UIViewController /** Wave transition * diff --git a/Source/AMWaveViewController.m b/Source/AMWaveViewController.m index 8e9fce9..9911b55 100644 --- a/Source/AMWaveViewController.m +++ b/Source/AMWaveViewController.m @@ -3,7 +3,7 @@ // Demo // // Created by Andrea Mazzini on 16/04/14. -// Copyright (c) 2014 Fancy Pixel. All rights reserved. +// Copyright (c) 2015 Fancy Pixel. All rights reserved. // #import "AMWaveViewController.h" @@ -14,20 +14,17 @@ @interface AMWaveViewController () @implementation AMWaveViewController -- (void)viewDidLoad -{ +- (void)viewDidLoad { [super viewDidLoad]; } -- (void)viewDidAppear:(BOOL)animated -{ +- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self.navigationController setDelegate:self]; [self.interactive attachInteractiveGestureToNavigationController:self.navigationController]; } -- (void)viewDidDisappear:(BOOL)animated -{ +- (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; [self.interactive detachInteractiveGesture]; } @@ -35,21 +32,18 @@ - (void)viewDidDisappear:(BOOL)animated - (id)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController*)fromVC - toViewController:(UIViewController*)toVC -{ + toViewController:(UIViewController*)toVC { if (operation != UINavigationControllerOperationNone) { return [AMWaveTransition transitionWithOperation:operation andTransitionType:AMWaveTransitionTypeNervous]; } return nil; } -- (NSArray *)visibleCells -{ +- (NSArray *)visibleCells { return nil; } -- (void)dealloc -{ +- (void)dealloc { [self.navigationController setDelegate:nil]; }