All Projects → Rightpoint → Shift

Rightpoint / Shift

Licence: other
A library of custom iOS View Controller Animations and Interactions written in Swift.

Programming Languages

swift
15916 projects
objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Shift

Carthage compatible CocoaPods compatible

A library of custom iOS View Controller Animations and Interactions written in Swift.

Installation with Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following commands:

brew update
brew install carthage

To integrate Shift into your Xcode project using Carthage, specify it in your Cartfile:

github "raizlabs/shift"

Installation with CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects.

To integrate Shift into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'Shift'

Usage

First, make sure you import the Shift module: import Shift.

The rest is easy. If you are pushing a view controller to the navigation stack, follow these three steps:

  • Set your navigation controller's delegate :
navigationController?.delegate = self
  • Store the transition on your view controller:
var currentTransition: UIViewControllerAnimatedTransitioning?
  • Extend your view controller to implement UINavigationControllerDelegateTransitioning. In your implementation, make sure to set the currentTransition:
extension ViewController: UINavigationControllerDelegate {

    func navigationController(navigationController: UINavigationController,
        animationControllerForOperation operation: UINavigationControllerOperation,
        fromViewController fromVC: UIViewController,
        toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {

        if (operation == .Push && fromVC == self) {
            /*
             * set currentTransition here
             */
        }
        else if (operation == .Pop && toVC == self) {
        }

        return currentTransition
    }
}

SplitTransition (Push/Pop)


Overview

SplitTransition exposes 5 key properties:

  1. screenshotScope - (optional, defaults to .View) - determines whether top and bottom views are sourced from container view or entire window
  2. splitLocation (optional, defaults to 0.0) - y coordinate where the top and bottom views part
  3. transitionDuration (optional, defaults to 1.0) - duration (in seconds) of the transition animation
  4. transitionDelay (optional, defaults to 0.0) - delay (in seconds) before the start of the transition animation
  5. transitionType (optional, defaults to .Push) - .Push, .Pop, or .Interactive. Setting transitionType to .Interactive will allow users to control the progress of the transition with a drag gesture.

Set these properties in your implementation of UINavigationControllerDelegateTransitioning:

func navigationController(navigationController: UINavigationController,
    animationControllerForOperation operation: UINavigationControllerOperation,
    fromViewController fromVC: UIViewController,
    toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {

    if (operation == .Push && fromVC == self) {
        let splitTransition = SplitTransitionController()
        splitTransition.transitionDuration = 2.0
        splitTransition.transitionType = .Push
        splitTransition.splitLocation = currentCell != nil ? CGRectGetMidY(currentCell!.frame) : CGRectGetMidY(view.frame)
        currentTransition = splitTransition
    }
    else if (operation == .Pop && toVC == self) {
        currentTransition?.transitionType = .Pop
    }

    return currentTransition
}

SplitTransition (Present/Dismiss)

Using SplitTransition to present a view controller modally is simple. For the presented view controller, set modalPresentationStyle to .Custom. For the SplitTransition, set transitionType to .Presentation, passing a presenting view controller and a presented view controller into the constructor. In addition, set your presented view controller's transitioningDelegate to the newly created SplitTransition.

// Configure destination view controller
let destinationViewController = UIViewController()
destinationViewController.modalPresentationStyle = .Custom

// Configure transition
let currentTransition = SplitTransition()
currentTransition?.transitionType = .Presentation(self, destinationViewController)

// Set transitioning delegate on destination view controller
destinationViewController.transitioningDelegate = currentTransition

Lastly, in presentViewController's completion handler set transitionType to .Dismiss, again passing in a presented view controller and a presenting view controller:

presentViewController(destinationViewController, animated: true) { [weak self] () -> Void in
    guard let vc = self,
    presentedVC = self?.presentedViewController else {
        debugPrint("SplitTransitionAnimatedPresentDismissViewControllerViewController has been deallocated")
        return
    }

    // After presentation has finished, update transitionType on currentTransition
    vc.currentTransition?.transitionType = .Dismissal(presentedVC, vc)
}

ZoomPushTransition


Overview

ZoomPushTransition exposes 2 key properties:

  1. transitionTime - duration (in seconds) of the transition
  2. scaleChangePct - a transform which scales the destination view controller's view by `(sx, sy)' at the start of the transition

Set these properties in your view controller's implementation of UINavigationControllerDelegate:

    func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        let zoomPushTransition = ZoomPushTransition()
        zoomPushTransition.transitionTime = 0.35
        zoomPushTransition.scaleChangePct = 0.33
        return zoomPushTransition
    }
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].