Model animations integrated with Facebook and Twitter-B

Source: Internet
Author: User

This animation. Thank the great God for sharing


Jppoppresentanimation.gif

To achieve this function in two steps: The first step, the first implementation of this animation. In the second step, 0 lines of code are integrated into the project. That is, you do not have to change any of the original project code, as long as the written animation code dragged into the project, all the model will have this animation.

  - (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion

All right, you ready? Start now.

First step: Implement this animation first
  • First of all, let's analyze this animation, this animation is in the model when the current controller's view, and then in the model process to reduce the size of the view. Then get this view at dismiss and restore it to its original size. That's all.

  • How do I get the current controller's view in the model animation? This is simple, as long as you set the animation style to custom and become the proxy for the popup animation, like this:

    self.modalTransitionStyle = UIModalPresentationCustom;viewControllerToPresent.transitioningDelegate = self;

    Then, in the proxy method, ask the provider of the transition animation, and then you can create a new Jptransitionmanager as the provider for the transition animation.

    //ask the provider of the Transition animation-(Nullable id <uiviewcontrolleranimatedtransitioning>) Animationcontrollerforpresentedcontroller: (uiviewcontroller *) presented Presentingcontroller: (uiviewcontroller *) Presenting Sourcecontroller: (uiviewcontroller *) source;-(nullable id < uiviewcontrolleranimatedtransitioning>) Animationcontrollerfordismissedcontroller: (uiviewcontroller *) dismissed;    
  • In this transition animation provider, we inherit the NSObject and then follow
    Uiviewcontrolleranimatedtransitioning protocol, and then implement these two methods in the protocol:

    - (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext;- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext;

    The first method is to ask for the duration of the animation. In the second method we can get the context Transitioncontext for the model animation, In the context we can get the current controller and the upcoming controller by: Uitransitioncontextfromviewcontrollerkey and Uitransitioncontexttoviewcontrollerkey two keys 。

  • The controller has been taken, we can get the controller corresponding to the view to animate.

Step two: 0 lines of code integrated into the project

Why emphasize 0 lines of code integration into a project?

    • At the beginning of the code, the project boss did not say that the animation, your project is almost over, he said this animation is very good, we also do a bar (programmer turned: xxx dirty words). This time you have written hundreds of model animation code, you can not be one to find to change it?
    • Hundreds of line you changed the end, you think finally finished, this thing is over, the product manager one months later came to say, this function we still cut off. (The programmer loudly: XXXXXX is dirty).

Therefore, low-coupling easy integration is particularly important at this time.

In order to deal with such requirements, the hook scheme is used to solve the problem with runtime. Hook is the meaning of a hook.

    • We're going to hook up all of the system's model animations with this hook, and then hook out the pop animations we wrote ourselves.
    • Then the dynamic method Exchange is used to replace the model animation of the system with the implementation of its own pop animation.
    • So later, when we call the model animation of the system, we will actually go to the method implementation to find our own pop animation to execute. That's why you can integrate this functionality with 0 lines of code.
    • It is also possible that we do not need pop animations in some cases, such as a photo browser. This is rarely the case, so you just have to write very little code to call our own pop animations. When we call our own pop animations, our hooks look for the system's model animations to execute.

The idea is here, specific implementation details, you also need to go to GitHub to download the demo.



Wen/newpan (author of Jane's book)
Original link: http://www.jianshu.com/p/910d7825f06a
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

Model animations integrated with Facebook and Twitter-B

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.