TransitionRouter
helps you to create custom transitions between controllers fast and easy. Interactive prototype is available here.
How to use TransitionRouter
? Simple as ABC! You need to create a router with one of transition type like:
let topRouter = TransitionRouter(type: .top)
Also you can create your own custom transition. Just create an object that conforms TransitionAnimator
protocol and create a router with your object:
let fadeRouter = TransitionRouter(type: .custom(animator: FadeTransitionAnimator()))
When you need to start any custom transition, set the router as transitioningDelegate
of the controller you want to present:
let vc = SecondViewController()
vc.transitioningDelegate = selectedRouter
present(vc, animated: true)
Of course, you can customize options of default transitions:
- duration: animation duration
- option:
UIViewAnimationOptions
- delay: delay before animation
- percentage: max percentage to finish interactive transition.
Animation options can be changed via options
property.
To create interactive transition you need to create router with interactive
parameter:
let leftInteractiveRouter = TransitionRouter(type: .left, interactive: true)
or set directly via property:
leftInteractiveRouter.interactive = true
Сertainly, you can control progress of transition. Create UIPanGestureRecognizer
or its subclass and set the router:
let leftRecognizer = UIScreenEdgePanGestureRecognizer()
leftRecognizer.edges = .left
leftInteractiveRouter
.add(leftRecognizer)
.transition { [unowned self] router in
let vc = ColorViewController(color: .green)
vc.transitioningDelegate = router
self.present(vc, animated: true)
}
view.addGestureRecognizer(leftRecognizer)
You can update progress of transition manually:
leftInteractiveRouter.update { recognizer -> CGFloat in
let translation = recognizer.translation(in: recognizer.view!)
return translation.x / recognizer.view!.bounds.width * 0.5
}
Pay attention - for your custom animator you must set updating logic manually.
To run the example project, clone the repo, and run pod install
from the Example directory first.
github "artemnovichkov/TransitionRouter"
pod "TransitionRouter"
File > New > Project
Create a Package.swift
in a root directory.
import PackageDescription
let package = Package(
name: "NameOfYourPackage",
dependencies: [
.Package(url: "https://github.com/artemnovichkov/TransitionRouter", majorVersion: 0, minor: 1)
]
)
Run swift package fetch
Open the Xcode Project File. File > New > Target > Cocoa Touch Framework If you don't need Obj-C support remove the .h files in the navigator.
Go in Finder and drag & drop the sources from Packages/TransitionRouter/Sources
into your project and add it to the TransitionRouter target.
Link your Project to the TransitionRouter dependency. Select your main target and add the CocoaTouchFramework to the Linked Frameworks and Libraries in the General Tab.
Drag the Sources folder into your project. Download
Artem Novichkov, [email protected]
TransitionRouter is available under the MIT license. See the LICENSE file for more info.