The POP Material Motion family provides a bridge between Facebook's POP library and the Material Motion runtime.
- Swift 3
- Objective-C
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.
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
Import the framework:
@import MaterialMotionPop;
You will now have access to all of the APIs.
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
- How to animate a property with a SpringTo plan
- How to configure spring behavior
- How to pause a spring while a gesture recognizer is active
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#>)
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#>)
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#>)
We welcome contributions!
Check out our upcoming milestones.
Learn more about our team, our community, and our contributor essentials.
Licensed under the Apache 2.0 license. See LICENSE for details.