Convert Figma logo to code with AI

CosmicMind logoMotion

A library used to create beautiful animations and transitions for iOS.

1,766
117
1,766
4

Top Related Projects

A custom reusable circular / progress slider control for iOS application.

Material Design Floating Action Button in liquid state

:octocat: PaperOnboarding is a material design UI slider. Swift UI library by @Ramotion

:octocat: 📃 FoldingCell is an expanding content cell with animation made by @Ramotion

:octocat: ExpandingCollection is an animated material design UI card peek/pop controller. iOS library made by @Ramotion

:octocat: ⭕️ CircleMenu is a simple, elegant UI menu with a circular layout and material design animations. Swift UI library made by @Ramotion

Quick Overview

Motion is an animation and gesture library for iOS, written in Swift. It provides a set of tools and APIs to create smooth, interactive animations and gestures in iOS applications, making it easier for developers to implement complex UI interactions and transitions.

Pros

  • Simplifies the creation of complex animations and gestures
  • Offers a wide range of pre-built animations and transitions
  • Provides a clean and intuitive API for custom animations
  • Actively maintained and updated for the latest Swift versions

Cons

  • Limited to iOS platform, not available for other mobile or web platforms
  • May have a learning curve for developers new to animation libraries
  • Could potentially increase app size due to additional dependencies
  • Some advanced features might require in-depth knowledge of Core Animation

Code Examples

  1. Creating a simple fade animation:
let fadeAnimation = Motion.fade()
fadeAnimation.timingFunction = .easeInOut
fadeAnimation.duration = 0.5

view.animate(fadeAnimation)
  1. Implementing a spring animation:
let springAnimation = Motion.spring(velocity: 0.5, damping: 0.7)
springAnimation.duration = 1.0

button.animate(springAnimation)
  1. Adding a pan gesture recognizer:
let panGesture = Motion.pan()
panGesture.addTarget(self, action: #selector(handlePan(_:)))

view.addGestureRecognizer(panGesture)

Getting Started

To get started with Motion, follow these steps:

  1. Add Motion to your project using CocoaPods or Swift Package Manager.
  2. Import Motion in your Swift file:
import Motion
  1. Create an animation and apply it to a view:
let animation = Motion.fade()
animation.duration = 0.5
myView.animate(animation)
  1. Run your app and see the animation in action!

Competitor Comparisons

A custom reusable circular / progress slider control for iOS application.

Pros of HGCircularSlider

  • Focused specifically on circular slider functionality
  • Lightweight and easy to integrate
  • Customizable appearance with various options

Cons of HGCircularSlider

  • Limited to circular slider functionality
  • Less comprehensive animation and interaction features
  • Smaller community and fewer updates

Code Comparison

HGCircularSlider:

let circularSlider = HGCircularSlider(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
circularSlider.minimumValue = 0.0
circularSlider.maximumValue = 100.0
view.addSubview(circularSlider)

Motion:

let button = Button()
button.animate(.scale(1.5))
button.animate(.rotate(45))
view.layout(button).center()

HGCircularSlider is focused on creating circular sliders with a simple API, while Motion provides a more comprehensive animation and layout framework. HGCircularSlider is ideal for projects requiring specific circular slider functionality, whereas Motion offers a broader range of animation and interaction capabilities for various UI elements.

Material Design Floating Action Button in liquid state

Pros of LiquidFloatingActionButton

  • Focused on creating a specific, visually appealing floating action button with liquid animation
  • Lightweight and easy to implement for a single purpose
  • Customizable appearance with various properties for color, size, and animation

Cons of LiquidFloatingActionButton

  • Limited in scope, only provides a floating action button component
  • Less flexibility for creating complex animations or transitions
  • May require additional libraries for more advanced UI interactions

Code Comparison

LiquidFloatingActionButton:

let button = LiquidFloatingActionButton(frame: CGRect(x: 0, y: 0, width: 56, height: 56))
button.center = self.view.center
button.animateStyle = .up
button.color = .blue
self.view.addSubview(button)

Motion:

let button = FABButton(image: Icon.add)
button.pulseColor = .white
button.backgroundColor = .blue
view.layout(button).bottom(24).right(24).size(56)

Summary

LiquidFloatingActionButton is a specialized library for creating a visually appealing floating action button with liquid animation. It's easy to implement but limited in scope. Motion, on the other hand, is a more comprehensive animation and UI framework that offers greater flexibility and a wider range of components and animations. The choice between the two depends on the specific needs of your project and the desired level of customization and functionality.

:octocat: PaperOnboarding is a material design UI slider. Swift UI library by @Ramotion

Pros of paper-onboarding

  • Focused specifically on onboarding UI, providing a streamlined solution for this use case
  • Offers a visually appealing paper-like animation effect
  • Lightweight and easy to integrate into existing projects

Cons of paper-onboarding

  • Limited in scope compared to Motion's broader animation capabilities
  • Less customization options for advanced use cases
  • Fewer active contributors and updates

Code Comparison

paper-onboarding:

let onboarding = PaperOnboarding()
onboarding.dataSource = self
onboarding.delegate = self
view.addSubview(onboarding)

Motion:

let animation = Motion.animate(duration: 0.5) {
    view.alpha = 0.5
    view.scale = 0.8
}
animation.completion = { finished in
    print("Animation completed")
}

Summary

paper-onboarding is a specialized library for creating engaging onboarding experiences with a unique paper-like animation effect. It's easy to use but limited in scope. Motion, on the other hand, offers a more comprehensive animation framework with greater flexibility and customization options. While paper-onboarding excels in its niche, Motion provides a broader set of tools for various animation needs in iOS development.

:octocat: 📃 FoldingCell is an expanding content cell with animation made by @Ramotion

Pros of folding-cell

  • Focused on a specific UI component (folding cell), making it easier to implement for this particular use case
  • Lightweight and simple to integrate into existing projects
  • Provides a visually appealing and interactive animation out of the box

Cons of folding-cell

  • Limited in scope compared to Motion's broader animation framework
  • Less flexibility for creating custom animations beyond the folding cell effect
  • May require additional libraries or custom code for more complex UI interactions

Code Comparison

folding-cell:

let cell = FoldingCell()
cell.itemCount = 4
cell.backgroundColor = .clear

cell.foregroundView = foregroundView
cell.containerView = containerView

Motion:

let animation = Motion.animate(.fade)
animation.timingFunction = .easeInOut
animation.duration = 0.5

button.motion([.fade, .scale(0.5)])
Motion.animate(animation)

While folding-cell provides a specific, ready-to-use UI component, Motion offers a more flexible and comprehensive animation framework for various UI elements and transitions. The choice between the two depends on the specific project requirements and the desired level of customization.

:octocat: ExpandingCollection is an animated material design UI card peek/pop controller. iOS library made by @Ramotion

Pros of expanding-collection

  • Focused on a specific UI component (expanding cards collection)
  • Simpler implementation for its specific use case
  • Includes a demo app showcasing the component's functionality

Cons of expanding-collection

  • Limited in scope compared to Motion's broader animation framework
  • Less flexibility for custom animations outside of the expanding cards concept
  • Fewer stars and contributors on GitHub, potentially indicating less community support

Code Comparison

expanding-collection:

let viewController = ExpandingViewController(style: .fill)
viewController.itemSize = CGSize(width: 256, height: 335)
viewController.collectionView?.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)

Motion:

let v1 = UIView()
v1.animate(.fadeIn)
v1.animate(.translate(x: 100, y: 100))
v1.animate(.spin)

The code snippets demonstrate the different focus areas of the two libraries. expanding-collection is centered around configuring and customizing the expanding cards view controller, while Motion provides a more general-purpose animation framework with chainable animation methods for various UI elements.

:octocat: ⭕️ CircleMenu is a simple, elegant UI menu with a circular layout and material design animations. Swift UI library made by @Ramotion

Pros of circle-menu

  • Focused on a specific UI component (circular menu), making it easier to implement for this particular use case
  • Lightweight and simple to integrate, with minimal dependencies
  • Provides a visually appealing and interactive circular menu animation out-of-the-box

Cons of circle-menu

  • Limited in scope compared to Motion's broader animation framework
  • Less flexibility for customizing animations beyond the circular menu concept
  • Fewer active contributors and updates, potentially leading to compatibility issues with newer iOS versions

Code Comparison

Motion:

let animation = Motion(duration: 0.5)
animation.animate(to: view) { (view) in
    view.alpha = 1
    view.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
}

circle-menu:

let circleMenu = CircleMenu(
    frame: view.bounds,
    normalIcon:"icon_menu",
    selectedIcon:"icon_close",
    buttonsCount: 4,
    duration: 4,
    distance: 120)
view.addSubview(circleMenu)

While Motion offers a more general-purpose animation framework, circle-menu provides a ready-to-use circular menu component with predefined animations. Motion allows for greater customization of various animations, whereas circle-menu focuses on delivering a specific UI element with less complexity in implementation.

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

Motion Logo

Motion

Welcome to Motion, a library used to create beautiful animations and transitions for views, layers, and view controllers.

Photos Sample

Take a look at a sample Photos project to get started.

Photos

Who is Motion for?

Motion is designed for beginner to expert developers. For beginners, you will be exposed to very powerful APIs that would take time and experience to develop on your own, and experts will appreciate the time saved by using Motion.

What you will learn

You will learn how to use Motion with a general introduction to fundamental concepts and easy to use code snippets.

Transitions

Motion transitions a source view to a destination view using a linking identifier property named motionIdentifier.

MatchTranslateRotateArcScale
MatchTranslateRotateArcScale

Example Usage

An example of transitioning from one view controller to another with transitions:

View Controller 1

greyView.motionIdentifier = "foo"
orangeView.motionIdentifier = "bar"

View Controller 2

isMotionEnabled = true
greyView.motionIdentifier = "foo"
orangeView.motionIdentifier = "bar"
orangeView.transition(.translate(x: -100))

The above code snippet tells the source views in view controller 1 to link to the destination views in view controller 2 using the motionIdentifier. Animations may be added to views during a transition using the transition method. The transition method accepts MotionTransition structs that configure the view's animation.

UINavigationController, UITabBarController, and UIViewController Transitions

Motion offers default transitions that may be used by UINavigationControllers, UITabBarControllers, and presenting UIViewControllers.

PushSlideZoomSlideCoverPageFadeZoom
PushSlideZoom SlideCoverPageFadeZoom

Example Usage

An example of transitioning from one view controller to another using a UINavigationController with a zoom transition:

UINavigationController

class AppNavigationController: UINavigationController {
    open override func viewDidLoad() {
        super.viewDidLoad()
        isMotionEnabled = true
        motionNavigationTransitionType = .zoom
    }
}

To add an automatic reverse transition, use autoReverse.

motionNavigationTransitionType = .autoReverse(presenting: .zoom)

Animations

Motion provides the building blocks necessary to create stunning animations without much effort. Motion's animation API will make maintenance a breeze and changes even easier. To create an animation, use the animate method of a view or layer and pass in a list of MotionAnimation structs. MotionAnimation structs are configurable values that describe how to animate a property or group of properties.

Background ColorCorner RadiusFadeRotateSizeSpring
Background ColorCorner RadiusFadeRotateSizeSpring
Border Color & Border WidthDepthPositionScaleSpinTranslate
Border Color & Border WidthDepthPositionScaleSpinTranslate

Example Usage

let box = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
box.backgroundColor = .blue

box.animate(.background(color: .red), .rotate(180), .delay(1))

In the above code example, a box view is created with a width of 100, height of 100, and an initial background color of blue. Following the general creation of the view, the Motion animate method is passed MotionAnimation structs that tell the view to animate to a red background color and rotate 180 degrees after a delay of 1 second. That's pretty much the general idea of creating animations.

Requirements

  • iOS 8.0+
  • Xcode 8.0+

Communication

  • If you need help, use Stack Overflow. (Tag 'cosmicmind')
  • If you'd like to ask a general question, use Stack Overflow.
  • If you found a bug, and can provide steps to reliably reproduce it, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Installation

Embedded frameworks require a minimum deployment target of iOS 8.

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate Motion's core features into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'Motion', '~> 3.1.0'

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

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

github "CosmicMind/Motion"

Run carthage update to build the framework and drag the built Motion.framework into your Xcode project.

Change Log

Motion is a growing project and will encounter changes throughout its development. It is recommended that the Change Log be reviewed prior to updating versions.

License

The MIT License (MIT)

Copyright (C) 2019, CosmicMind, Inc. http://cosmicmind.com. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.