# Custom iOS Transitions with a Two-Line API

Language: en
Canonical: [Custom iOS Transitions with a Two-Line API](<https://allluckly.cn/en/journal/2016-11-14-custom-ios-transitions-with-a-two-line-api/>)
中文：[中文 HTML](<https://allluckly.cn/%E6%8A%95%E7%A8%BF/tougao70>)
English: [English HTML](<https://allluckly.cn/en/journal/2016-11-14-custom-ios-transitions-with-a-two-line-api/>)
Published: 2016-11-14T00:00:00+08:00
Modified: 2026-10-23T10:34:15+08:00
Author: 逆流丶而上

Introduces WTKTransitionAnimate, selecting transitions through a navigation delegate and factory methods. It combines drag gestures with percentage-based progress to implement an interactive back transition and explains the organization behind the wrapper.

Originally credited to 逆流丶而上; edited and archived by Bison.

[Source listed in the original](<http://www.jianshu.com/p/f99d72bf8452>)

English translation of the [Chinese original](<https://allluckly.cn/%E6%8A%95%E7%A8%BF/tougao70>), translated on 2026-10-23. The article body uses automated translation; app descriptions, historical reading notes and video subtitles receive separate editorial checks. Original publication dates, attribution, code and version notes are retained.

**Before you read** This technical note dates from 2015–2017. The examples have not been rerun as part of this archive update. Published in 2016, the article uses the custom transition APIs introduced in iOS 7.

![1](<https://allluckly.cn/images/blog/tuogao/tougao70/1.gif>)

Editor: [Bison](<https://allluckly.cn/en/>)  
 Source: [逆流丶而上](<http://www.jianshu.com/p/f99d72bf8452>)

iOS7 introduced new transition APIs through protocols,, id interface for developers. Complex APIs and cumbersome implementation discourage many developers.

I wrapped several common transitions for simpler use. Search CocoaPods for WTKTransitionAnimate and import it.

![1](<https://allluckly.cn/images/blog/tuogao/tougao70/2.png>)

## Usage

Import #import

```
self.navigationController.delegate = [WTKTransition shareManager];
[WTKTransition shareManager].animationType = WTKAnimateTypeKuGou;
```

Set navigationController’s delegate to the WTKTransition singleton; animationType specifies the transition:

```
typedef NS_ENUM(NSInteger,WTKAnimateType)
{
    WTKAnimateTypeDefault = 0,
    /// 两个导航栏不一致
    WTKAnimateTypeDiffNavi,
    ///仿酷狗
    WTKAnimateTypeKuGou,
    ///圆形遮罩
    WTKAnimateTypeRound,
    ///椭圆遮罩
    WTKAnimateTypeOval,
    ///仿斗鱼
    WTKAnimateTypeDouYu,
};
```

## Implementation

The singleton implements two transition delegate methods, using a factory to create subclasses for animateType and concrete animations. UIPercentDrivenInteractiveTransition provides interaction. A pan gesture on viewController.view updates its state. Normally the gesture belongs in a parent controller; for easier usage, a category uses runtime associations and intercepts viewDidLoad to add the back gesture.

WTKAnimateTypeRound centres each animation on the tap coordinate. Obtain the tap location and use it as the next push animation’s centre. There are two ways to obtain it:

1. Subclass Appdelegate, implement sendEvent and obtain coordinates from Event.

2. Use a category to intercept sendEvent through runtime and obtain coordinates from Event. This simplifies WTKTransitionAnimation usage. Cancelling the swipe-back gesture also posts WTK\_CANCEL\_POP.

[Download the demo](<https://github.com/wangtongke/WTKTransitionAnimate>)

---

Recommended reading: [Implement an iOS launch-screen advertisement in minutes](<https://allluckly.cn/en/journal/2016-06-12-adding-a-launch-advertisement-to-an-ios-app/>)

