Convert Figma logo to code with AI

material-motion logomaterial-motion-swift

A toolkit for building responsive motion using Core Animation.

1,420
79
1,420
56

Top Related Projects

An iOS library to natively render After Effects vector animations

19,660

An extensible iOS and OS X animation library, useful for physics-based interactions.

5,371

KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS.

:octocat: RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion

3,453

Animated top menu for UITableView / UICollectionView / UIScrollView written in Swift

Quick Overview

The material-motion/material-motion-swift repository is a collection of Swift libraries that provide a set of tools and APIs for building animations and transitions in iOS applications. It is part of the Material Motion project, which aims to create a unified and extensible animation system for the Material Design ecosystem.

Pros

  • Modular Design: The project is divided into several independent libraries, allowing developers to pick and choose the components they need for their specific use case.
  • Declarative Approach: The libraries encourage a declarative style of programming, making it easier to reason about and compose complex animations.
  • Extensibility: The project is designed to be extensible, allowing developers to create their own custom motion primitives and integrate them into the existing ecosystem.
  • Performance-Oriented: The libraries are optimized for performance, leveraging native iOS animation APIs and techniques to ensure smooth and efficient animations.

Cons

  • Learning Curve: The project's declarative approach and extensive API can have a steep learning curve for developers who are more familiar with traditional imperative animation techniques.
  • Limited Documentation: The project's documentation, while generally good, could be more comprehensive and provide more examples and use cases.
  • Ecosystem Maturity: As a relatively new project, the Material Motion ecosystem may not have the same level of community support and third-party integrations as more established animation libraries.
  • Dependency Management: The project's modular design can lead to a more complex dependency management process, especially when integrating multiple Material Motion libraries into a project.

Code Examples

Creating a Simple Animation

import MaterialMotion

let animation = PositionAnimation(
    from: CGPoint(x: 100, y: 100),
    to: CGPoint(x: 200, y: 200),
    duration: 1.0
)

let motionGroup = MotionGroup(animations: [animation])
motionGroup.startAnimation()

This code creates a simple position animation that moves a view from (100, 100) to (200, 200) over the course of 1 second.

Composing Animations

import MaterialMotion

let scaleAnimation = ScaleAnimation(
    from: 1.0,
    to: 1.5,
    duration: 0.5
)

let rotationAnimation = RotationAnimation(
    from: 0.0,
    to: .pi / 4,
    duration: 0.5
)

let motionGroup = MotionGroup(animations: [scaleAnimation, rotationAnimation])
motionGroup.startAnimation()

This code creates a motion group that combines a scale animation and a rotation animation, allowing you to compose multiple animations together.

Customizing Animations

import MaterialMotion

let animation = PositionAnimation(
    from: CGPoint(x: 100, y: 100),
    to: CGPoint(x: 200, y: 200),
    duration: 1.0
)

animation.timingFunction = .easeInOut
animation.delay = 0.5
animation.isReversible = true

let motionGroup = MotionGroup(animations: [animation])
motionGroup.startAnimation()

This code demonstrates how to customize the properties of an individual animation, such as the timing function, delay, and reversibility.

Getting Started

To get started with the Material Motion Swift libraries, follow these steps:

  1. Add the desired Material Motion libraries to your project using a dependency manager like CocoaPods or Carthage.
# Example CocoaPods Podfile
pod 'MaterialMotion'
pod 'MaterialMotionTransitions'
  1. Import the necessary Material Motion modules in your Swift files.
import MaterialMotion
import MaterialMotionTransitions
  1. Create and configure your animations using the provided APIs, as shown in the code examples above.

  2. Start the animations by calling the startAnimation() method on your MotionGroup or MotionAnimator instances.

  3. Explore the additional Material Motion libraries and features, such as transitions, gesture-driven animations, and custom motion primitives, to build more complex and engaging user experiences.

Refer to the project's [README](https://github.com/material-motion/material

Competitor Comparisons

An iOS library to natively render After Effects vector animations

Pros of Lottie-iOS

  • Extensive Documentation: Lottie-iOS has a comprehensive set of documentation, including detailed guides, API references, and examples, making it easier for developers to get started and integrate the library into their projects.
  • Active Community: Lottie-iOS has a large and active community, with regular updates, bug fixes, and contributions from a wide range of developers.
  • Versatility: Lottie-iOS supports a wide range of animation formats, including those created in Adobe After Effects, making it a versatile choice for various animation needs.

Cons of Lottie-iOS

  • Dependency on External Tools: Lottie-iOS requires the use of external tools, such as Adobe After Effects, to create and export animations, which may not be accessible or preferred by all developers.
  • Performance Concerns: Depending on the complexity of the animations, Lottie-iOS may have performance implications, especially on older or less powerful devices.
  • Limited Customization: While Lottie-iOS provides a good level of customization, it may not offer the same level of control and flexibility as a custom animation solution.

Code Comparison

Here's a brief code comparison between Lottie-iOS and Material Motion Swift:

Lottie-iOS (adding an animation):

let animationView = LottieAnimationView(name: "animation_name")
animationView.frame = view.bounds
animationView.contentMode = .scaleAspectFit
animationView.loopMode = .loop
view.addSubview(animationView)
animationView.play()

Material Motion Swift (creating a transition):

let transition = MotionTransition()
transition.duration = 0.5
transition.motionIdentifier = "my-transition"
transition.perform { context in
    // Transition animation logic
}
19,660

An extensible iOS and OS X animation library, useful for physics-based interactions.

Pros of Pop

  • Mature and Widely Adopted: Pop has been around since 2011 and has a large user base, making it a mature and well-established library.
  • Extensive Documentation: Pop has comprehensive documentation, including detailed guides and examples, making it easier to get started and integrate into projects.
  • Flexible and Customizable: Pop provides a wide range of customization options, allowing developers to fine-tune the animations to their specific needs.

Cons of Pop

  • Objective-C Only: Pop is written in Objective-C, which may be a limitation for developers who prefer to work in Swift.
  • Potential Maintenance Concerns: Facebook has archived the Pop repository, indicating that it is no longer actively maintained, which could be a concern for long-term projects.

Code Comparison

Here's a brief code comparison between Pop and Material Motion Swift:

Pop:

POPSpringAnimation *anim = [POPSpringAnimation animation];
anim.property = [POPAnimatableProperty propertyWithName:kPOPLayerPositionX];
anim.toValue = @(200);
anim.springBounciness = 20;
anim.springSpeed = 20;
[layer pop_addAnimation:anim forKey:@"position"];

Material Motion Swift:

let motion = MotionAnimator()
motion.addMotion(
    MotionTween(
        property: .position,
        from: CGPoint(x: 0, y: 0),
        to: CGPoint(x: 200, y: 0),
        duration: 0.5
    )
)
motion.startAnimations()

The key differences are that Material Motion Swift uses a more declarative approach, with a focus on defining the desired motion rather than the underlying animation parameters.

5,371

KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS.

Pros of Koloda

  • Swipeable Cards: Koloda provides a swipeable card interface, which can be useful for various types of content, such as dating apps or content discovery.
  • Customizable Animations: Koloda offers a range of customizable animations for the card swiping interactions, allowing developers to create unique and engaging user experiences.
  • Flexible Configuration: Koloda can be easily configured to suit different use cases, with options for card size, swiping direction, and more.

Cons of Koloda

  • Limited Functionality: Compared to Material Motion Swift, Koloda is more focused on the swipeable card interface and may lack the broader set of motion-related features and tools.
  • Dependency on UIKit: Koloda is built on top of UIKit, which may limit its compatibility with newer Apple frameworks or cross-platform development.

Code Comparison

Material Motion Swift:

let motion = MotionAnimator()
motion.animate(
  to: .position(CGPoint(x: 100, y: 100)),
  duration: 0.5,
  curve: .easeInOut
)

Koloda:

let card = KolodaView(frame: view.bounds)
card.dataSource = self
card.delegate = self
view.addSubview(card)

:octocat: RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion

Pros of Animated Tab Bar

  • Animated Tab Bar provides a visually appealing and interactive tab bar experience, which can enhance the overall user interface of an application.
  • The library is well-documented and easy to integrate into an iOS project, making it accessible for developers of all skill levels.
  • Animated Tab Bar offers a variety of pre-built animation styles, allowing developers to quickly and easily customize the tab bar to fit their application's design.

Cons of Animated Tab Bar

  • Animated Tab Bar is a third-party library, which means that it may not receive the same level of support and maintenance as a built-in iOS framework.
  • The library may not be as flexible or customizable as a more low-level solution, such as Material Motion, which allows for more fine-grained control over the animation and interaction behavior.
  • Animated Tab Bar may have a larger footprint in terms of file size and dependencies, which could impact the overall performance of an application.

Code Comparison

Material Motion Swift

let motion = MotionAnimator()
motion.animate(
  to: .position(CGPoint(x: 100, y: 100)),
  duration: 0.5
)

Animated Tab Bar

let tabBarController = AnimatedTabBarController()
tabBarController.items = [
  UITabBarItem(title: "Home", image: UIImage(named: "home"), tag: 0),
  UITabBarItem(title: "Search", image: UIImage(named: "search"), tag: 1)
]
tabBarController.animationOptions = .transitionFade
3,453

Animated top menu for UITableView / UICollectionView / UIScrollView written in Swift

Pros of Persei

  • Smooth Animations: Persei provides a smooth and visually appealing scrolling experience with its custom animation effects.
  • Customizable Appearance: The library offers a high degree of customization, allowing developers to tailor the appearance and behavior of the scrolling elements to match their app's design.
  • Responsive Design: Persei is designed to work well across different screen sizes and devices, ensuring a consistent user experience.

Cons of Persei

  • Limited Functionality: Compared to Material Motion Swift, Persei is more focused on providing a specific set of scrolling-related features, rather than a comprehensive motion design framework.
  • Dependency on External Libraries: Persei relies on the use of external libraries, such as Masonry, which may increase the overall complexity of the project setup.

Code Comparison

Material Motion Swift (5 lines)

let motion = MotionAnimator()
let position = PositionAnimator(motion: motion)
let scale = ScaleAnimator(motion: motion)

position.target = CGPoint(x: 100, y: 100)
scale.target = 1.5

Persei (5 lines)

let scrollView = PerseiBannerView(frame: view.bounds)
scrollView.backgroundColor = .white
scrollView.delegate = self
scrollView.addSubview(contentView)
scrollView.startAutoScroll()

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Material Motion

Reactive motion driven by Core Animation.

Swift 3.1.x iOS 9.0+ Build Status codecov CocoaPods Compatible Platform Docs Chat

This library includes a variety of ready-to-use interactions. Interactions are registered to an instance of MotionRuntime:

// Store me for as long as the interactions should take effect.
let runtime = MotionRuntime(containerView: <#view#>)
InteractionSnippet
ArcMove
let arcMove = ArcMove()
arcMove.from.value = <#from#>
arcMove.to.value = <#to#>
runtime.add(arcMove, to: <#view#>)
ChangeDirection
runtime.add(ChangeDirection(withVelocityOf: gesture),
            to: <#direction#>)
DirectlyManipulable
runtime.add(DirectlyManipulable(), to: <#view#>)
Draggable
runtime.add(Draggable(), to: <#view#>)
Rotatable
runtime.add(Rotatable(), to: <#view#>)
Scalable
runtime.add(Scalable(), to: <#view#>)
SetPositionOnTap
runtime.add(SetPositionOnTap(),
            to: runtime.get(<#view#>.layer).position)
Spring
let spring = Spring()
spring.destination.value = <#initial destination#>
runtime.add(spring, to: <#view#>)
Tossable
let tossable = Tossable()
tossable.spring.destination.value = <#initial destination#>
runtime.add(tossable, to: <#view#>)
Tween
runtime.add(Tween(duration: 0.5, values: [1, 0]),
            to: runtime.get(<#view#>.layer).opacity)

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

pod 'MaterialMotion'

You will need to add use_frameworks! to your Podfile in order use Material Motion in your swift app.

A simple Podfile might look like so:

project 'MyApp/MyApp.xcodeproj'

use_frameworks!

target 'MyApp' do
  pod 'MaterialMotion'
end

Then run the following command:

pod install

Usage

Import the framework:

import MaterialMotion

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/material-motion-swift.git
cd material-motion-swift
pod install
open MaterialMotion.xcworkspace

Case studies

Carousel

A carousel with pages that scale in and fade out in reaction to their scroll position.

View the source.

Contextual transition

A contextual view can be used to create continuity during transitions between view controllers. In this case study the selected photo is the contextual view. It's possible to flick the view to dismiss it using the tossable interaction.

Makes use of: Draggable, Tossable, Transition, TransitionSpring, Tween.

View the source.

Floating action button transition

A floating action button transition is a type of contextual transition that animates a mask outward from a floating button.

Makes use of: Transition and Tween.

View the source.

Material expansion

A Material Design transition using asymetric transformations.

Makes use of: Tween.

View the source.

Modal dialog

A modal dialog that's presented over the existing context and is dismissable using gestures.

Makes use of: Tossable and TransitionSpring.

View the source.

Pull down to dismiss

A modal scroll view controller that can be dismissed with a drag gesture.

Makes use of: Tossable and TransitionSpring.

View the source.

Sticker picker

Each sticker is individually directly manipulable, meaning they can be dragged, rotated, and scaled using multitouch gestures.

Makes use of: DirectlyManipulable.

View the source.

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.