TransitionTreasury is a viewController transition framework in Swift.
You can see http://transitiontreasury.com
- 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
- [TransitionTreasury 3.0 Migration Guide](https://github.com/DianQK/TransitionTreasury/blob/master/Documentation/TransitionTreasury 3.0 Migration Guide.md)
- iOS 8.0+
- Xcode 7.1+
- 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. :]
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', '~> 3.0.1'
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 'TransitionTreasury/Animations'
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.
If we need to push FirstViewController
to SecondViewController
, SecondViewController
should conform NavgationTransitionable
, 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: TRPushTransitionMethod, completion: (() -> Void)?)
, 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, TRTransition {
var tr_transition: TRNavgationTransitionDelegate?
func pop() {
tr_popViewController()
}
}
When you need to pop, just call public func tr_popViewController(completion: (() -> Void)? = nil) -> UIViewController?
.
If we present MainViewController
to ModalViewController
:
MainViewController
should conformModalTransitionDelegate
, and addvar tr_transition: TRViewControllerTransitionDelegate?
- Add
weak var modalDelegate: ModalViewControllerDelegate?
forModalViewController
.
Example:
/// MainViewController.swift
class MainViewController: UIViewController, ModalTransitionDelegate {
var tr_transition: 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 implementedfunc modalViewControllerDismiss(callbackData data:AnyObject?)
. If you don't want to useModalTransitionDelegate
, you can useViewControllerTransitionable
which only for Animation. Warning:
You shouldn't usetr_dismissViewController()
in your ModalViewController. Please usedelegate
. I have implented this, just usemodalDelegate?.modalViewControllerDismiss(callbackData: ["data":"back"])
. For more, you can read Dismissing a Presented View Controller.
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 animation, see Custom Animation.
Just conform TRViewControllerAnimatedTransitioning
. If you need interactive, conform TransitionInteractiveable
.
About write your animation, you can read Animation-Guide, I am happy that you will share your animation for this project.
Also, you can see TransitionTreasury/TransitionAnimation
, there are some Animations. You can write follow this.
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: TRPushTransitionMethod.Fade, statusBarStyle: UIStatusBarStyle = .Default)
// Present & Dismiss
tr_presentViewController(viewControllerToPresent: UIViewController, method: TRPresentTransitionMethod.Fade, statusBarStyle: UIStatusBarStyle = .Default)
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.
Just Add this code:
tabBarController.tr_transitionDelegate = TRTabBarTransitionDelegate(method: TRTabBarTransitionDelegate.Slide)
Note: If you need
delegate
, please usetr_delegate
.
You can see Demo/TabBarDemo
.
TransitionTreasury is released under the MIT license. See LICENSE for details.