Skip to content

basszhx3x/TransitionTreasury

 
 

Repository files navigation

TransitionTreasury

TransitionTreasury is a viewController transition framework in Swift.

You can see transitiontreasury.com

Features

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

Requirements

  • iOS 8.0+
  • Xcode 7.1+

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

CocoaPods 0.39.0+ is required to build TransitionTreasury.

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

use_frameworks!
pod 'TransitionTreasury'

Then, run the following command:

$ pod install

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

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

Usage

Make a Push

If we need to push FirstViewController to SecondViewController, SecondViewController should conform TRTransition, and add code var tr_transition: 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(viewcontroller: UIViewController, method: TRPushMethod, completion: (() -> Void)?), like Apple method. About method parameter, see transitiontreasury.com.

Example:

class OMINViewController: UIViewController, TRTransition {
    
    var tr_transition: TRNavgationTransitionDelegate?

    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        if let view = touches.first?.view {
            let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("OMINViewController")
            navigationController?.tr_pushViewController(vc, method: .OMIN(keyView: view), completion: {
                print("Push finish")
            })
        }
    }
}

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 ModalViewControllerDelegate, and add var tr_transition: TRViewControllerTransitionDelegate?
  • ModalViewController should conform ModalViewControllerDelegate, and add weak var modalDelegate: ModalViewControllerDelegate?

Example:

/// MainViewController.swift
var tr_transition: TRViewControllerTransitionDelegate?

@IBAction func tr_presentVC(sender: UIButton) {
        let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ModalViewController") as! ModalViewController
        vc.modalDelegate = self
        let nav = UINavigationController(rootViewController: vc)
        tr_presentViewController(nav, method: .Twitter, completion: nil)
    }

/// ModalViewController.swift
weak var modalDelegate: ModalViewControllerDelegate?

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
    @IBAction func pop(sender: AnyObject) {
        modalDelegate?.modalViewControllerDismiss(callbackData: ["data":"back"])
    }

Note:
If you don't need callbackData, maybe you haven't implemented func modalViewControllerDismiss(callbackData data:Dictionary<String,AnyObject>?).
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

Custom Animation

Now, there is just Custom Animation, other usages are coming after next version.

Like Basic-Usage, just replace method paramters to Custom(TRViewControllerAnimatedTransitioning), provide your animation object.

Note:
Thanks to Swift's Enum. I can write more concise code.
You also can use exist transition animation, just a joke~, here just be used to show an example.

Example:

navigationController?.tr_pushViewController(vc, method: .Custom(OMINTransitionAnimation(key: view)), completion: {
                print("Push finished")
            })

About write your animation, you can read Animation-Guide, I happy to you will share your animation for this project.

Status Bar Style

@Available >~ 1.1.0

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

Then like Basic Usage, just add param statusBarStyle:

// Push & Pop
tr_pushViewController(viewController: UIViewController, method: TRPushMethod, statusBarStyle: UIStatusBarStyle = .Default)    
tr_pushViewController(viewController: UIViewController, method: TRPushMethod, statusBarStyle: UIStatusBarStyle = .Default, completion: (() -> Void)? = nil)

// Present & Dismiss
tr_presentViewController(viewControllerToPresent: UIViewController, method: TRPresentMethod, statusBarStyle: UIStatusBarStyle = .Default)
tr_presentViewController(viewControllerToPresent: UIViewController, method: TRPresentMethod, statusBarStyle: UIStatusBarStyle = .Default, completion: (() -> Void)? = nil)

License

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

About

Easier way to push your viewController.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 98.5%
  • Other 1.5%