Skip to content

Archived February 16, 2017 :: POP plan types for Apple devices

License

Notifications You must be signed in to change notification settings

material-motion-archive/pop-swift

Repository files navigation

POP for Material Motion (Swift)

Build Status codecov CocoaPods Compatible Platform Docs

The POP Material Motion family provides a bridge between Facebook's POP library and the Material Motion runtime.

Supported languages

  • Swift 3
  • Objective-C

Features

SpringTo uses POP springs to animate properties using spring physics driven on the main thread of the application.

For example, you might use a SpringTo plan to move a view's position to a specific position on screen:

let springTo = SpringTo("position", destination: CGPoint(x: 10, y: 10))
scheduler.addPlan(springTo, to: view.layer)

SpringTo supports a subset of key paths on certain types:

CALayer

  • backgroundColor
  • bounds
  • cornerRadius
  • borderWidth
  • borderColor
  • opacity
  • position
  • position.x
  • position.y
  • transform.rotation.z
  • transform.rotation.x
  • transform.rotation.y
  • transform.scale.x
  • transform.scale
  • transform.scale.y
  • bounds.size
  • sublayerTransform.scale
  • sublayerTransform.translation.x
  • sublayerTransform.translation
  • sublayerTransform.translation.y
  • sublayerTransform.translation.z
  • transform.translation.x
  • transform.translation
  • transform.translation.y
  • transform.translation.z
  • zPosition
  • shadowColor
  • shadowOffset
  • shadowOpacity
  • shadowRadius

CAShapeLayer

  • strokeStart
  • strokeEnd
  • strokeColor
  • fillColor
  • lineWidth
  • lineDashPhase

NSLayoutConstraint

  • constant

UIView

  • alpha
  • backgroundColor
  • bounds
  • center
  • frame
  • transform.scale.x
  • transform.scale
  • transform.scale.y
  • bounds.size
  • tintColor

UIScrollView

  • contentOffset
  • contentSize
  • zoomScale
  • contentInset
  • scrollIndicatorInsets

UINavigationBar

  • barTintColor

UILabel

  • textColor

Read the feature request for supporting more key paths.

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 MaterialMotionPop to your Podfile:

pod 'MaterialMotionPop'

Then run the following command:

pod install

Usage

Import the framework:

@import MaterialMotionPop;

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/pop-swift.git
cd pop-swift
pod install
open MaterialMotionPop.xcworkspace

Guides

  1. How to animate a property with a SpringTo plan
  2. How to configure spring behavior
  3. How to pause a spring while a gesture recognizer is active

How to animate a property with a SpringTo plan

Code snippets:

In Objective-C:

MDMSpringTo *springTo = [[MDMSpringTo alloc] initWithProperty:"<#property key path#>"
                                                  destination:<#Destination value#>];
[scheduler addPlan:springTo to:<#Object#>];

In Swift:

let springTo = SpringTo("<#property key path#>", destination: <#Destination value#>)
scheduler.addPlan(springTo, to: <#Object#>)

How to configure spring behavior

A spring's behavior can be configured by setting a SpringConfiguration object on the SpringTo instance.

Code snippets:

In Objective-C:

springTo.configuration = [[MDMSpringConfiguration alloc] initWithTension:<#tension#>
                                                                friction:<#friction#>];

In Swift:

springTo.configuration = SpringConfiguration(tension: <#tension#>, friction: <#friction#>)

How to pause a spring while a gesture recognizer is active

Code snippets:

In Objective-C:

MDMPauseSpring *pauseSpring = [[MDMPauseSpring alloc] initWithProperty:"<#property key path#>"
                                                     gestureRecognizer:<#gesture recognizer#>];
[scheduler addPlan:springTo to:<#Object#>];

In Swift:

let springTo = MDMPauseSpring("<#property key path#>", whileActive: <#gesture recognizer#>)
scheduler.addPlan(springTo, to: <#Object#>)

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.