Skip to content

raoxb/TransitionTreasury

 
 

Repository files navigation

TransitionTreasury

Build Status Twitter

TransitionTreasury is a viewController transition framework in Swift.

Features

  • Push & Present
  • Easy create transition & extension
  • Support completion callback
  • Support modal viewController data callback
  • Support Custom Transition
  • 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

Carthage

Usage

Make a Push

Your viewController must conform TRTransition. Code like this:

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")
            })
        }
    }
}

Make a Present

Your MainViewController must conform ModalViewControllerDelegate, and your ModalViewController must conform MainViewControllerDelegate. Code like this:

/// 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.
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.setNavigationBarHidden(false, animated: true)
    }
    
    @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

License

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

About

Easier way to push your viewController.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%