vctransitionslibrary– Customizing the Library for iOS interactive transition animations

Source: Internet
Author: User
Tags exit in

Brief introduction

Vctransitionslibrary provides a number of transition animations that are suitable for use in scenarios such as in-stack, out-of-stack, modal, and so on. It itself provides a well-defined transition animation library that you can drag directly into your project, as well as many "interactive controllers" with different transitions animation effects. You can use these controllers directly with custom animation effects, rather than controlling your interactions with your own control.

Project home: Vctransitionslibrary

Latest example: Click to download

Note: The transition animation for the Custom view controller is IOS7 + via Uiviewcontrollertransitioningdelegate protocol, uinavigationcontrollerdelegate protocol and The Uitabbarcontrollerdelegate protocol provides system-level support. The purpose of this library is to define common animation effects and encapsulate common interactions, simplifying the encoding of iOS interactive transition animations!

Quick StartOperating Environment
    • IOS 7+

    • ARC

InstallationInstalling with CocoaPods
Pod "Vctransitionslibrary"
Manual Installation

Take the documents AnimationControllers and InteractionControllers 文件夹下所有代码复制 go to the project.

Use

When customizing transition animations, there are two classes of key classes:

    • Animation Controller – This class is used to implement custom animations. But when you declare that you want to use custom animations, you should provide an animation controller. This class implements the desired animation and notifies the framework when it is finished.

    • Interactive Controller – This class is used to manage interactions-interactions that are usually controlled by a gesture that is empty, allowing the user to navigate through the two view controllers by swiping, swiping, or performing other actions. It must be noted that the interactive controller allows navigation cancellation, for example, A user can suddenly change his mind when he is navigating to a page, and then cancels the operation.

Note: animations and interactions are completely independent, which means you can use the interactive controller independently on any other custom controller-cool!

Using the animation controller

The Animationcontrollers folder offers a number of animation controllers that can be integrated into your project:

Custom modal controller display/hidden animations

The Uiviewcontrollertransitioningdelegate protocol is used to provide an animation controller when the modal controller is shown/hidden. When a view controller is displayed or hidden in a modal mode, Its Transitioningdelegate property is used to provide support for the Uiviewcontrollertransitioningdelegate protocol. A class that acts as a proxy role, by AnimationControllerForPresentedController:presentingController:sourceController: Method returns the animation of the modal display, byanimationControllerForDismissedController: 返回模态消失时的动画即可.

Customizing transition animations for top navigation

Uinavigationcontroller has a

Id<uinavigationcontrollerdelegate> delegate property. Just let its proxy pass through the Navigationcontroller: AnimationControllerForOperation:fromViewController:toViewController: Returns an animated effect.

in order to set both the stack/stack to the appropriate animation effect (or, when the stack/stack can be used in the opposite direction of the animation), you can refer to the following code:

-(id<uiviewcontrolleranimatedtransitioning>) Navigationcontroller: (uinavigationcontr Oller *) Navigationcontroller animationcontrollerforoperation: (uinavigationcontrolleroperation) Operation F Romviewcontroller: (Uiviewcontroller *) Fromvc Toviewcontroller: (Uiviewcontroller *) ToVC {//out of the stack, to reverse the animation party    To. _animationcontroller.reverse = operation = = Uinavigationcontrolleroperationpop; return _animationcontroller;}
Customizing transition animations for bottom tab bar navigation

Uitabbarcontroller has a id<uitabbarcontrollerdelegate> delegate property, just let its proxy pass the Tabbarcontroller: Animationcontrollerfortransitionfromviewcontroller:toviewcontroller: Returns an animated effect.

To give the animation a proper orientation, 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;} 
Using the interactive controller

The interactive controller and animation controller can be used together to achieve interactivity with animated transitions, such as allowing users to control navigation between pages via gestures. The interactive controller allows the user to move forward, backward, and even exit in a transition animation.

The interactive controller is responsible for adding gestures to the view and is responsible for navigating the user when they use a gesture.

Interaction when the modal controller disappears

uiviewcontrollertransitioningdelegate protocol is also used to provide support for interactive transitions. Here is an example of a combination of sweep gestures and page-flipping animations:

Instance variables, usually initialized in your initialization method ceflipanimationcontroller *_animationcontroller; ceswipeinteractioncontroller *_interactioncontroller;-  (id<uiviewcontrolleranimatedtransitioning >)       animationcontrollerforpresentedcontroller: (UIViewController *) presented                            presentingcontroller: (UIViewController  *) presenting                                sourcecontroller: ( uiviewcontroller *) source {    //  allows the interactive controller to bind its gesture recognizer .     [_interactioncontroller wiretoviewcontroller:presented                                       foroperation:ceinteractionoperationdismiss];       _ Animationcontroller.reverse = no;    return _animationcontroller;} -  (id<uiviewcontrolleranimatedtransitioning>)       Animationcontrollerfordismissedcontroller: (uiviewcontroller *) dismissed {    _ Animationcontroller.reverse = yes;    return _animationcontroller;} -  (id<uiviewcontrollerinteractivetransitioning>)             interactionControllerForDismissal:                  (id<uiviewcontrolleranimatedtransitioning>) animator {     //  If an interactive controller is triggered, use it directly. Returns nil to enable the user to return directly by clicking on a button;Outgoing Interactive controller .    return _interactioncontroller.interactioninprogress                 ? _interactioncontroller  : nil;}
Interaction at the time of the stack

Uinavigationcontrollerdelegate also has a way to provide support for interactive transitions. A typical pattern similar to the above code:

  instance variables, which are typically initialized in your initialization method. ceflipanimationcontroller *_animationcontroller; ceswipeinteractioncontroller *_interactioncontroller;-  (id<uiviewcontrolleranimatedtransitioning >)                   Navigationcontroller: (uinavigationcontroller *) navigationcontroller       Animationcontrollerforoperation: (uinavigationcontrolleroperation) operation                    fromviewcontroller: ( uiviewcontroller *) fromvc                      toviewcontroller: (uiviewcontroller *) toVC {     //  bind the interactive controller to your view controller .    [_interactioncontroller  wiretoviewcontroller:tovc                                     forOperation:CEInteractionOperationPop];     _animationController.reverse = operation ==  Uinavigationcontrolleroperationpop;    return _animationcontroller;} -  (id <uiviewcontrollerinteractivetransitioning>)                            Navigationcontroller: (uinavigationcontroller *) navigationcontroller    Interactioncontrollerforanimationcontroller: (id <uiviewcontrolleranimatedtransitioning>) animationcontroller {    //If an interactive controller is triggered, use it directly. Returns nil to enable the user to return directly by clicking on a button, without triggering an interactive controller.      return _interactioncontroller.interactioninprogress                 ? _ Interactioncontroller : nil;}
Interaction for tab Bar Controller switching

The Uitabbarcontrollerdelegate protocol also provides support for interactive transitions. However, because the proxy method is not executed during the initial initialization, all other ways to bind the interactive controller, such as KVO, are required:

@implementation  tabbarviewcontroller {    cefoldanimationcontroller *_ Animationcontroller;    ceswipeinteractioncontroller *_swipeinteractioncontroller;} -  (ID) Initwithcoder: (nscoder *) adecoder {    if  (self = [ Super initwithcoder:adecoder])  {        self.delegate =  self;        //  Create interactive/animation controller .         _swipeInteractionController = [CESwipeInteractionController new];         _animationController = [CEFoldAnimationController new];         _animationController.folds = 3;         //  Monitor the change of selected selectors using the Observer mode.         [ 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"] )     &nBsp {        //  bind the interaction controller to the view controller .         [_swipeInteractionController wireToViewController:self.selectedViewController                                                foroperation:ceinteractionoperationtab];    }}-   (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;} -(id<uiviewcontrollerinteractivetransitioning>) Tabbarcontroller: (uitabbarcontroller *) Tabbarcontroller interactioncontrollerforanimationcontroller: (id<uiviewcontrolleranimatedtransitioning >) animationcontroller{    return _swipeinteractioncontroller.interactioninprogress  ? _swipeinteractioncontroller : nil;} @end


vctransitionslibrary– Customizing the Library for iOS interactive transition animations

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.