TransitionRouter

master

🚡 Simple custom transition framework
artemnovichkov/TransitionRouter

TransitionRouter

Swift 5.0+ Carthage compatible Version License

TransitionRouter helps you to create custom transitions between controllers fast and easy. Interactive prototype is available here.

TransitionRouter

Using

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)

‼️Don't forget about strong reference for the router!‼️

Configuration

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.

Interactive transitions

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.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

Carthage

github "artemnovichkov/TransitionRouter"

CocoaPods

pod "TransitionRouter"

Swift Package Manager

Step 1

File > New > Project

Step 2

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

Step 3

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.

Step 4

Go in Finder and drag & drop the sources from Packages/TransitionRouter/Sources into your project and add it to the TransitionRouter target.

Step 5

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.

Manual

Drag the Sources folder into your project. Download

Author

Artem Novichkov, novichkoff93@gmail.com

License

TransitionRouter is available under the MIT license. See the LICENSE file for more info.

Description

  • Swift Tools 5.1.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sat Oct 19 2024 19:23:15 GMT-0900 (Hawaii-Aleutian Daylight Time)