• This repository has been archived on 02/Jul/2023
  • Stars
    star
    2,092
  • Rank 21,302 (Top 0.5 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easier way to push your viewController.

TransitionTreasury

TransitionTreasury is a viewController transition framework in Swift.

You can see https://transitiontreasury.com

Features

  • Push & Present & TabBar transition animation
  • Easy create transition & extension
  • Support completion callback
  • Support modal viewController data callback
  • Support Custom Transition
  • Support Update Status Bar Style
  • Support Push & Present & TabBar Gesture.
  • Complete Documentation

Migration Guides

Requirements

  • iOS 8.0+
  • Xcode 10.0+

Communication

  • If you need help or found a bug, open an issue.
  • If you have a new transition animation or want to contribute, submit a pull request. :]

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate TransitionTreasury into your Xcode project using CocoaPods, specify it in your Podfile:

use_frameworks!
pod 'TransitionTreasury', '~> 7.0'

Then, run the following command:

$ pod install

In any file you'd like to use TransitionTreasury in, don't forget to import the framework with import TransitionTreasury.

For TransitionAnimation extensions, this project will include them as dependencies. You can do this via CocoaPods subspecs.

pod 'TransitionAnimation', '~> 7.0'

### Carthage

Carthage is a decentralized dependency manager for Cocoa application. To install the carthage tool, you can use Homebrew.

$ brew update
$ brew install carthage

To integrate TransitionTreasury into your Xcode project using Carthage, specify it in your Cartfile:

github "DianQK/TransitionTreasury"

Then, run the following command to build the TransitionTreasury framework:

$ carthage update

At last, you need to set up your Xcode project manually to add the TransitionTreasury framework.

On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.

On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script with the following content:

/usr/local/bin/carthage copy-frameworks

and add the paths to the frameworks you want to use under “Input Files”:

$(SRCROOT)/Carthage/Build/iOS/TransitionTreasury.framework
$(SRCROOT)/Carthage/Build/iOS/TransitionAnimation.framework // If need

For more information about how to use Carthage, please see its project page.

Usage

You can check out Example or Demo .
Don't forget pod install for Example .

Make a Push

If we need to push FirstViewController to SecondViewController, SecondViewController should conform NavgationTransitionable, and add code var tr_pushTransition: TRNavgationTransitionDelegate?, I need use this property to retain animation object. Of course, you can use this do more, but it is dangerous.

When you need to push, just call public func tr_pushViewController<T : UIViewController where T : NavgationTransitionable>(viewController: T, method: TransitionAnimationable, statusBarStyle: TransitionTreasury.TRStatusBarStyle = default, completion: (() -> Void)? = default), like Apple method. About method parameter, see transitiontreasury.com.

Example:

/// FirstViewController.swift
class FirstViewController: UIViewController {

    func push() {
        let vc = SecondViewController()
        navigationController?.tr_pushViewController(vc, method: TRPushTransitionMethod.fade, completion: {
                print("Push finish")
            })
    }
}

/// SecondViewController.swift
class SecondViewController: UIViewController, NavgationTransitionable {

    var tr_pushTransition: TRNavgationTransitionDelegate?

    func pop() {
        tr_popViewController()
    }
}

When you need to pop, just call public func tr_popViewController(completion: (() -> Void)? = nil) -> UIViewController?.

Make a Present

If we present MainViewController to ModalViewController:

  • MainViewController should conform ModalTransitionDelegate, and add var tr_presentTransition: TRViewControllerTransitionDelegate?
  • Add weak var modalDelegate: ModalViewControllerDelegate? for ModalViewController.

Example:

/// MainViewController.swift
class MainViewController: UIViewController, ModalTransitionDelegate {

    var tr_presentTransition: TRViewControllerTransitionDelegate?

    func present() {
        let vc = ModalViewController()
        vc.modalDelegate = self // Don't forget to set modalDelegate
        tr_presentViewController(vc, method: TRPresentTransitionMethod.Fade, completion: {
                print("Present finished.")
            })
    }
}

/// ModalViewController.swift
class ModalViewController: UIViewController {

    weak var modalDelegate: ModalViewControllerDelegate?

    func dismiss() {
        modalDelegate?.modalViewControllerDismiss(callbackData: nil)
    }
}

if you need callbackData , your MianViewController should implement :

func modalViewControllerDismiss(interactive interactive: Bool, callbackData data:AnyObject?)

// or

func modalViewControllerDismiss(callbackData data:AnyObject?)

interactive just for interactive dismiss, for more see Advanced Usage.

Note:
If you don't need callbackData, maybe you haven't implemented func modalViewControllerDismiss(callbackData data:AnyObject?). If you don't want to use ModalTransitionDelegate, you can use ViewControllerTransitionable which only for Animation. Warning:
You shouldn't use tr_dismissViewController() in your ModalViewController. Please use delegate. I have implented this, just use modalDelegate?.modalViewControllerDismiss(callbackData: ["data":"back"]). For more, you can read Dismissing a Presented View Controller.

Advanced Usage

Create Your Transition Enum (Recommended!!!!)

Maybe like this:

enum DemoTransition {
    case FadePush
    case TwitterPresent
    case SlideTabBar
}

extension DemoTransition: TransitionAnimationable {
    func transitionAnimation() -> TRViewControllerAnimatedTransitioning {
        switch self {
        case .FadePush:
            return FadeTransitionAnimation()
        case .TwitterPresent :
            return TwitterTransitionAnimation()
        case .SlideTabBar :
            return SlideTransitionAnimation()
        }
    }
}

Then you can use your transition, maybe like this:

tr_pushViewController(viewController: viewController, method: DemoTransition.FadePush)
tr_presentViewController(viewControllerToPresent: viewController, method: DemoTransition.TwitterPresent)

Well, you can create your own animation, see Custom Animation.

Custom Animation

Just conform to TRViewControllerAnimatedTransitioning. If you need interactive functionality, conform to TransitionInteractiveable.

About writing your own animation, you can read Animation-Guide, I would be happy if you would share your animation for this project. Also, check out TransitionTreasury/TransitionAnimation, there are some Animations there. You can write follow this.

Status Bar Style

If you want to update the status bar style, you should add the key View controller-based status bar appearance in your info.plist, and set its value to false.

Then, like in Basic Usage, just add param statusBarStyle:

// Push & Pop
tr_pushViewController(viewController: UIViewController, method: TRPushTransitionMethod.fade, statusBarStyle: UIStatusBarStyle = .Default)    

// Present & Dismiss
tr_presentViewController(viewControllerToPresent: UIViewController, method: TRPresentTransitionMethod.Fade, statusBarStyle: UIStatusBarStyle = .Default)

Interactive Transition Animation

See TransitionTreasuryDemo Scheme:

func interactiveTransition(sender: UIPanGestureRecognizer) {
        switch sender.state {
        case .Began :
            guard sender.translationInView(view).y > 0 else {
                break
            }
            let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ModalViewController") as! ModalViewController
            vc.modalDelegate = self
            tr_presentViewController(vc, method: TRPresentTransitionMethod.Scanbot(present: sender, dismiss: vc.dismissGestureRecognizer), completion: {
                print("Present finished")
            })
        default : break
        }
    }

Warning: Make sure you just call tr_presentViewController(_:_:_:) once.

TabBar Transition Animation

Just add this code:

tabBarController.tr_transitionDelegate = TRTabBarTransitionDelegate(method: TRTabBarTransitionDelegate.Slide)

Note: If you need delegate, please use tr_delegate.

You can see Demo/TabBarDemo.

License

TransitionTreasury is released under the MIT license. See LICENSE for details.

More Repositories

1

Flix

iOS reusable form library in Swift.
Swift
728
star
2

LearnRxSwift

Swift
494
star
3

DQKFreezeWindowView

A freeze window effect view for iOS
Objective-C
361
star
4

rx-sample-code

Swift
166
star
5

TrelloNavigation

https://dribbble.com/shots/2114816-Trello-Navigation
Swift
118
star
6

uuplugin

UU 加速插件 docker 版本
Dockerfile
80
star
7

GroupTableSeparatorFix

Swift
66
star
8

DevOnPods

Ruby
61
star
9

HybridDemo

A hybrid project for iOS, Vue and React.
Swift
40
star
10

RouterBuilder

Swift
33
star
11

Sketch2Code

Swift
24
star
12

magisk-wireguard-auto-connect

Auto turn on and off WireGuard by using the ip monitor command. Turn it off when you are home and on when you are away.
Shell
18
star
13

LTOGlobalMachineOutliner

Ruby
13
star
14

FuckKeyboard

Deal the fuck keyboard
Objective-C
13
star
15

Router

Swift
12
star
16

ruslin-android

A simple notes application that supports syncing notes using a self-hosted Joplin server.
Kotlin
11
star
17

RxSwiftTreeSelect

Swift
9
star
18

rx-redux-sample-code

Swift
9
star
19

RxLogger

Swift
8
star
20

MeetRxSwift

Swift
8
star
21

wechat-archive

微信归档
Rust
7
star
22

debug-ipa

Shell
7
star
23

StuQ-RxSwift

Swift
7
star
24

RxExtensions

Swift
6
star
25

UploadImageDemo

Swift
6
star
26

openconnect-snell

Dockerfile
5
star
27

RefreshSingleCell

Swift
4
star
28

ld64-build

Makefile
4
star
29

SwiftDebug

打造一个愉快的 Swift Debug 控制台
Swift
4
star
30

Use-popToViewController

Swift
4
star
31

change-mach-o-symbol

C
4
star
32

Expandable

http://7xokf3.com1.z0.glb.clouddn.com/Demo.mov
Swift
3
star
33

UMengAnalytics-NO-IDFA-Module

Ruby
3
star
34

my_slack_bot_demo

Python
3
star
35

miui_push_device_fake

Shell
3
star
36

HAP-IR-Demo

Swift
3
star
37

StudyUnwindSegue

Swift
2
star
38

dianqk.blog

2
star
39

TwoWayBind

Swift
1
star
40

errorOnNil

Swift
1
star
41

SectionSelect

Swift
1
star
42

GMTC-Swift-on-Pi

Swift
1
star
43

unseenmail

Notify via ntfy when unseen new emails arrive
Rust
1
star
44

DianQK

1
star
45

UseStaticFramework

Ruby
1
star
46

reproduce_outlined_function_use_live_x0

https://reviews.llvm.org/D112911
Objective-C
1
star
47

ft9201fingerprint-nix

1
star
48

Happy-Hacking-Web

JavaScript
1
star