preface

In the usual development, we usually use the default transition animation (Push and Present) when interface jump. After iOS7, apple opened the relevant API, so that we can customize the transition animation, so that the APP is more dynamic. This article will introduce my open source project a custom transition animation library WXSTransition use and part of the principle, through this library, a line of code can achieve transition animation, simple and easy to use, but also support multiple attribute modification, flexible expansion.

WXSTransition introduces the first version of WXSTransition. After a period of optimization, WXSTransition has made some changes and added some new things, such as: support for gesture return and new animation effects







The body of the

1. Animation effect 2. Use method 3

1. Animation effect

Compared to the previous version, some new animations have been added. Here are some of the renderings:




insideThenPush.gif





frgmentFromRight.gif





normalViewMove.gif





fragmentFromTop.gif


2. Method of use

A single line of code calls Push:

  [self.navigationController wxs_pushViewController:[[SecondViewController alloc] init] animationType:WXSTransitionAnimationTypePageTransition];Copy the code

Present:

[self wxs_presentViewController:[[PresentViewController alloc] init] animationType:WXSTransitionAnimationTypePageTransition  completion:nil];Copy the code

Including WXSTransitionAnimationTypePageTransition is animation type, can choose different types of animation by changing here.

If you want to modify properties such as animation time, you can do so by using the following methods:

[self.navigationController wxs_pushViewController:vc makeTransition:^(WXSTransitionProperty *transition) { transition.animationType = WXSTransitionAnimationTypePointSpreadPresent; transition.animationTime = 1;  transition.backGestureEnable = NO; transition.startView = cell.contentView; }];Copy the code

Compared with the previous version, add startView and targetView two attributes, so that the use of more uniform. All properties that can be changed are visible in WXSTransitionProperty.

/** * transitiion animation time */ @property (nonatomic,assign) NSTimeInterval animationTime; /** * transitiion type: push,pop,present,dismiss push,pop,present,dismiss */ @property (nonatomic,assign) WXSTransitionType transitionType; / * * * transitions animation type * transitiion animation type * / @ property (nonatomic, assign) WXSTransitionAnimationType animationType; /** * set YES to make back action of systerm */ @property (nonatomic,assign) BOOL isSysBackAnimation; /** * Set YES to enable gesture for back */ @property (nonatomic,assign) BOOL backGestureEnable; ** * Choose type of gesture for gesture back, default: WXSGestureTypePanRight */ @property (nonatomic,assign) WXSGestureType backGestureType; /** * UIView */ @property (nonatomic, strong) UIView *startView; /** * UIView */ @property (nonatomic, strong) UIView *targetView;Copy the code

3. Gesture return

Gesture return is a new and important feature. The renderings are as follows:




gestureSpread.gif


Now supports left, up, down, right four gestures to return, can be modified through the backGestureType property.

Principle:

(1), the first thing to realize UIViewControllerInteractiveTransitioning agreement through a class – WXSPercentDrivenInteractiveTransition to control the progress of gestures, and animation. (2) When the hand leaves the screen and the gesture ends, the transition animation needs to continue. At this time, CADisplayLink is used to complete the rest of the animation.

The specific implementation method can be viewed in the source code WXSTransition, I will take the time to write a detailed introduction.

After the language

In addition to the above changes, this version also modified and optimized the code structure, and solved some bugs, such as delegate conflict, etc. Here I would like to thank the students who are enthusiastic about raising bugs, and I still hope to have more technical exchanges in the future. If you are interested, you can visit WXSTransition Clone to have a look. If you find it helpful, please give a Star.