Code Monkey home page Code Monkey logo

transitionrouter's Introduction

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, [email protected]

License

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

transitionrouter's People

Contributors

artemnovichkov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

balao7

transitionrouter's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.