VCTransitionsLibrary-custom iOS interactive transfer animation library, ios transfer Animation

Source: Internet
Author: User

VCTransitionsLibrary-custom iOS interactive transfer animation library, ios transfer Animation
Introduction

VCTransitionsLibrary provides many transfer animations suitable for inbound, outbound, and modal controller switching. it provides a defined transfer animation library, which can be used directly in your project. It also provides many interactive controllers with different transfer animation effects ", you can directly use these controllers to work with Custom Animation effects, rather than controlling interactions by yourself.

Project homepage: VCTransitionsLibrary

Latest example: Click to download

Note: The Transition animation of the custom View Controller is iOS7 + system-level support provided by the UIViewControllerTransitioningDelegate protocol, UINavigationControllerDelegate protocol, and UITabBarControllerDelegate protocol. the significance of this library is to define common animation effects and encapsulate common interactive operations, which simplifies the coding of iOS interactive transfer animation!

Quick Start running environment
  • IOS 7 +
  • ARC
Install and use CocoaPods
pod "VCTransitionsLibrary"
Manual Installation

FileAnimationControllersAndCopy all codes in the InteractionControllers folderGo to the project.

Use

There are two key types of custom transition Animation:

  • Animation controller-This class is used to implement Custom Animation. but when you declare that you want to use a Custom Animation, you should provide an animation controller. this class will implement the required animation, and the framework will be notified upon completion.
  • Interactive controller-This class is used to manage interactions-interactions normally controlled by a gesture, allowing users to navigate two view controllers by sliding, swiping, or performing other operations. it must be noted that the interactive controller allows canceling navigation. For example, when a user is navigating to a page, he suddenly changes his mind and then cancels the operation.

Note: animation and interaction are completely independent, which means that you can independently use the interaction Controller on any other custom controller-cool!

Use an animation Controller

The AnimationControllers folder provides many animation controllers that can be integrated into your project:

Custom modal controller display/hide Animation

The UIViewControllerTransitioningDelegate protocol is used to provide an animation controller when the modal controller is displayed/hidden. when a View Controller is displayed or hidden by mode, its transitioningDelegate attribute is used to provide support for the UIViewControllerTransitioningDelegate protocol. class that acts as a proxy. The animation in the Mode Display is returned through the animationControllerForPresentedController: presentingController: sourceController: method.AnimationControllerForDismissedController: returns the animation when the modal disappears.

Custom transition animation for top navigation

UINavigationController has

Id <UINavigationControllerDelegate> delegate attribute. You only need to have its proxy return an animation effect through navigationController: animationControllerForOperation: fromViewController: toViewController.

You can refer to the following code to set the appropriate animation effects for both the stack and the inbound stack (or the opposite animation can be used for the outbound/inbound stack:

-(Id <strong>) navigationController: (UINavigationController *) navigationController animationControllerForOperation :( strong) operation fromViewController :( UIViewController *) fromVC toViewController :( UIViewController *) toVC {// when the stack is output, to reverse the animation direction. _ animationController. reverse = operation = UINavigationControllerOperationPop; return _ animationController ;}
Customize transition animation for the tab bar navigation at the bottom

UITabBarController has an id <UITabBarControllerDelegate> delegate attribute. You only need to make its proxy pass tabBarController: animationControllerForTransitionFromViewController: toViewController: to return an animation effect.

To give an animation a proper direction, you can compare the indexes of two view controllers:

- (id <UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController            animationControllerForTransitionFromViewController:(UIViewController *)fromVC                                              toViewController:(UIViewController *)toVC {    NSUInteger fromVCIndex = [tabBarController.viewControllers indexOfObject:fromVC];    NSUInteger toVCIndex = [tabBarController.viewControllers indexOfObject:toVC];    _animationController.reverse = fromVCIndex < toVCIndex;    return _animationController;}
Use an interactive Controller

The interaction controller can be used with the animation controller to achieve interactive animation transfer effects. For example, you can use gestures to control the navigation between pages. the interaction controller allows you to move forward, backward, or even quit in a transfer animation.

The interaction Controller is responsible for adding gestures to the view and performing corresponding navigation operations when a user uses a gesture.

Interaction when the modal controller disappears

The UIViewControllerTransitioningDelegate protocol is also used to provide support for interactive transfer. The following is an example of combining the cleaning gesture and flip Animation:

// Instance variables, usually initialize them in your initialization method CEFlipAnimationController * _ animationController; CESwipeInteractionController * _ interactionController;-(id <identifier>) animationControllerForPresentedController :( UIViewController *) presented presentingController :( UIViewController *) presenting sourceController :( UIViewController *) source {// allows the interaction controller to bind its gesture reader. [_ interactionController wireToViewControl Ler: presented forOperation: CEInteractionOperationDismiss]; _ animationController. reverse = NO; return _ animationController;}-(id <UIViewControllerAnimatedTransitioning>) animationControllerForDismissedController :( UIViewController *) dismissed {_ animationController. reverse = YES; return _ animationController;}-(id <UIViewControllerInteractiveTransitioning>) interactionControllerForDismissal: (id <UIVi EwControllerAnimatedTransitioning>) animator {// If an interactive controller is triggered, use it directly. nil is returned to allow users to directly return by clicking a button. At this time, the interaction controller is not triggered. return _ interactionController. interactionInProgress? _ InteractionController: nil ;}
Interaction during stack Export

UINavigationControllerDelegate also provides methods to support interactive transfer. A typical mode similar to the above Code:

// Instance variables, which are usually initialized in your initialization method. required * _ animationController; required * _ interactionController;-(id <strong>) navigationController :( UINavigationController *) navigationController completed :( strong) operation fromViewController :( UIViewController *) fromVC toViewController :( UIViewController *) toV C {// bind the interaction controller to your view controller. [_ interactionController wireToViewController: toVC forOperation: CEInteractionOperationPop]; _ animationController. reverse = operation = UINavigationControllerOperationPop; return _ animationController;}-(id <strong>) navigationController :( UINavigationController *) navigationController interactionControllerForAnimationController :( id <UIViewC OntrollerAnimatedTransitioning>) animationController {// If an interactive controller is triggered, use it directly. nil is returned to allow users to directly return by clicking a button. At this time, the interaction controller is not triggered. return _ interactionController. interactionInProgress? _ InteractionController: nil ;}
Used for interaction during controller switching in the label bar

The UITabBarControllerDelegate Protocol also supports interactive transfer. However, because the proxy method is not executed during initial initialization, all other methods are required to bind the interaction controller, such as KVO:

@ Implementation TabBarViewController {CEFoldAnimationController * _ animationController; required * _ swipeInteractionController;}-(id) Updated :( NSCoder *) aDecoder {if (self = [super initWithCoder: aDecoder. delegate = self; // create an interaction/animation controller. _ swipeInteractionController = [CESwipeInteractionController new]; _ animationController = [CEFoldAnimationController new]; _ animati OnController. folds = 3; // use the observer mode to monitor the changes of the selected selector. [self addObserver: self forKeyPath: @ "selectedViewController" options: NSKeyValueObservingOptionNew context: nil];} return self;} (void) observeValueForKeyPath :( NSString *) keyPath ofObject :( id) object change :( NSDictionary *) change context :( void *) context {if ([keyPath isEqualToString: @ "selectedViewController"]) {// bind the interaction controller to the View Controller. [_ swipeInteraction Controller wireToViewController: self. selectedViewController forOperation: Rule] ;}}- (id <rule>) tabBarController :( UITabBarController *) tabBarController labels :( UIViewController *) fromVC toViewController :( UIViewController *) toVC {NSUInteger fromVCIndex = [tabBarController. viewControllers indexOfObject: FromVC]; NSUInteger toVCIndex = [tabBarController. viewControllers indexOfObject: toVC]; _ animationController. reverse = fromVCIndex <toVCIndex; return _ animationController;}-(id <strong>) tabBarController :( UITabBarController *) tabBarController interactionControllerForAnimationController :( id <strong>) animation controller {return _ swipeInte RactionController. interactionInProgress? _ SwipeInteractionController: nil;} @ end

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.