material-motion-archive / transitions-objc

Archived February 16, 2017 :: Transitions for Apple Devices
Apache License 2.0
5 stars 1 forks source link

Material Motion Transitions for Apple Devices

Build Status codecov CocoaPods Compatible Platform Docs

Supported languages

Features

This library makes it possible to create UIViewController transitions using the Material Motion runtime.

Installation

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C and Swift libraries. CocoaPods automates the process of using third-party libraries in your projects. See the Getting Started guide for more information. You can install it with the following command:

gem install cocoapods

Add MaterialMotionTransitions to your Podfile:

pod 'MaterialMotionTransitions'

Then run the following command:

pod install

Usage

Import the framework:

@import MaterialMotionTransitions;

You will now have access to all of the APIs.

Example apps/unit tests

Check out a local copy of the repo to access the Catalog application by running the following commands:

git clone https://github.com/material-motion/transitions-objc.git
cd transitions-objc
pod install
open MaterialMotionTransitions.xcworkspace

Guides

  1. Architecture
  2. How to create a transition director
  3. How to use a director for a view controller transition

Architecture

The core aspects of this library consist of the following:

An object conforming to TransitionDirector is able to describe the plans that should occur during a UIViewController transition.

TransitionController is what allows you to decide which TransitionDirector should govern a particular transition.

How to create a transition director

Transition directors govern both the presentation and dismissal of a given view controller. An instance of a director is created each time a transition is initiated and thrown away upon the transition's completion.

Step 1: Create a new class that conforms to TransitionDirector

Be sure to store the provided MDMTransition object.

Code snippets:

In Objective-C:

@interface <# DirectorName #>TransitionDirector : NSObject <MDMTransitionDirector>
@end

@interface <# DirectorName #>TransitionDirector ()
@property(nonatomic, strong) MDMTransition *transition;
@end

@implementation <# DirectorName #>TransitionDirector

- (instancetype)initWithTransition:(MDMTransition *)transition {
  self = [super init];
  if (self) {
    _transition = transition;
  }
  return self;
}

- (void)setUp {
}

@end

In Swift:

class <# DirectorName #>TransitionDirector: NSObject, TransitionDirector {

  let transition: Transition
  required init(transition: Transition) {
    self.transition = transition
  }

  func setUp() {
  }
}

Step 2: Register motion in setUp

Register plans using the transition object's runtime.

Code snippets:

In Objective-C:

- (void)setUp {
  [self.transition.runtime addPlan:<#(nonnull NSObject<MDMPlan> *)#> to:<#(nonnull id)#>];
}

In Swift:

func setUp() {
  transition.runtime.addPlan(<#T##plan: Plan##Plan#>, to: <#T##Any#>)
}

How to use a director for a view controller transition

Every view controller has an associated mdm_transitionController instance. Set a TransitionDirector class type on the directorClass property. When you present the view controller, an instance of your TransitionDirector class will be created and its setUp method will be invoked.

Code snippets:

In Objective-C:

<#(nonnull UIViewController *)#>.mdm_transitionController.directorClass = [<# TransitionDirector #>TransitionDirector class];
[self presentViewController:<#(nonnull UIViewController *)#> animated:<#(BOOL)#> completion:<#^(void)completion#>];

In Swift:

<# UIViewController instance #>.mdm_transitionController.directorClass = <# TransitionDirector #>TransitionDirector.self
present(<#T##viewControllerToPresent: UIViewController##UIViewController#>, animated: <#T##Bool#>)

Contributing

We welcome contributions!

Check out our upcoming milestones.

Learn more about our team, our community, and our contributor essentials.

License

Licensed under the Apache 2.0 license. See LICENSE for details.