Convert Figma logo to code with AI

MengTo logoSpring

A library to simplify iOS animations in Swift.

14,077
1,802
14,077
165

Top Related Projects

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

:octocat:💧 A slider widget with a popup bubble displaying the precise value selected. Swift UI library made by @Ramotion

3,453

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

: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

Quick Overview

Spring is an animation library for iOS that makes it easy to create beautiful and responsive animations. It provides a simple and intuitive API for creating physics-based animations, allowing developers to add natural-looking motion to their iOS applications with minimal effort.

Pros

  • Easy to use and integrate into existing iOS projects
  • Provides physics-based animations for more realistic and natural-looking motion
  • Highly customizable with a wide range of animation properties
  • Lightweight and efficient, with minimal impact on app performance

Cons

  • Limited to iOS development, not available for other platforms
  • May require some understanding of physics concepts for advanced usage
  • Documentation could be more comprehensive for complex scenarios
  • Occasional issues with animation consistency across different iOS versions

Code Examples

Creating a simple spring animation:

let animation = Spring(duration: 0.5, animations: {
    view.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
})
animation.spring = 0.5
animation.animate()

Chaining multiple animations:

Spring.animate(duration: 1.0, animations: {
    view.alpha = 0.5
}) { _ in
    Spring.animate(duration: 0.5, animations: {
        view.alpha = 1.0
    })
}

Using Spring with Auto Layout constraints:

Spring.animate(duration: 0.8, animations: {
    self.heightConstraint.constant = 200
    self.view.layoutIfNeeded()
})

Getting Started

  1. Add Spring to your project using CocoaPods:
pod 'Spring', '~> 1.0.6'
  1. Import Spring in your Swift file:
import Spring
  1. Create a Spring animation:
let animation = Spring(duration: 0.7, animations: {
    // Your animation code here
})
animation.curve = "easeInOut"
animation.force = 1.0
animation.animate()
  1. For more advanced usage, refer to the Spring documentation and examples in the GitHub repository.

Competitor Comparisons

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

Pros of HGCircularSlider

  • Focused specifically on circular slider functionality
  • Customizable appearance with various properties
  • Supports both clockwise and counterclockwise rotation

Cons of HGCircularSlider

  • Limited to circular slider implementation
  • Less versatile for general animation purposes
  • Smaller community and fewer updates

Code Comparison

HGCircularSlider:

let circularSlider = HGCircularSlider(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
circularSlider.minimumValue = 0.0
circularSlider.maximumValue = 100.0
circularSlider.endPointValue = 50.0

Spring:

let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
Spring.animate(view) { view in
    view.x = 200
    view.scaleX = 2
    view.scaleY = 2
}

Spring is a more general-purpose animation framework for iOS, offering a wide range of animation options for various UI elements. It simplifies complex animations with a chainable syntax. HGCircularSlider, on the other hand, is specialized for creating circular sliders with customizable properties. While Spring provides broader animation capabilities, HGCircularSlider offers more focused functionality for specific circular slider needs.

:octocat:💧 A slider widget with a popup bubble displaying the precise value selected. Swift UI library made by @Ramotion

Pros of fluid-slider

  • Specialized for creating fluid and interactive slider components
  • Provides a more visually appealing and modern slider design
  • Offers customizable bubble labels for precise value display

Cons of fluid-slider

  • Limited to slider functionality, less versatile than Spring
  • Smaller community and fewer updates compared to Spring
  • May require more setup for basic slider implementation

Code Comparison

Spring:

let animation = CABasicAnimation(keyPath: "position.x")
animation.fromValue = view.layer.position.x
animation.toValue = view.layer.position.x + 100
animation.duration = 0.5
animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
view.layer.add(animation, forKey: "position")

fluid-slider:

let slider = Slider()
slider.attributedTextForFraction = { fraction in
    let formatter = NumberFormatter()
    formatter.maximumIntegerDigits = 3
    formatter.maximumFractionDigits = 0
    let string = formatter.string(from: (fraction * 500) as NSNumber) ?? ""
    return NSAttributedString(string: string)
}
slider.setMinimumLabelAttributedText(NSAttributedString(string: "0"))
slider.setMaximumLabelAttributedText(NSAttributedString(string: "500"))
slider.fraction = 0.5

Spring offers a more general-purpose animation framework, while fluid-slider focuses on creating a specific type of interactive slider component. Spring provides greater flexibility for various animations, whereas fluid-slider excels in creating visually appealing slider interfaces with less code for that particular use case.

3,453

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

Pros of Persei

  • Specifically designed for UICollectionView and UITableView, offering seamless integration
  • Provides a unique pull-to-refresh animation with customizable menu items
  • Lightweight and focused on a single functionality

Cons of Persei

  • Limited to pull-to-refresh functionality, while Spring offers a broader range of animations
  • Less actively maintained, with fewer recent updates compared to Spring
  • Smaller community and fewer resources available for support

Code Comparison

Persei:

let persei = Persei(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 64))
persei.delegate = self
persei.dataSource = self
tableView.addSubview(persei)

Spring:

let view = SpringView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
view.animation = "squeezeDown"
view.animate()

Summary

Persei is a specialized library for pull-to-refresh animations in UICollectionView and UITableView, offering a unique and customizable experience. Spring, on the other hand, provides a wider range of animation options for various UI elements. While Persei excels in its specific use case, Spring offers more versatility and active development. The choice between the two depends on the project's requirements and the desired level of customization for animations.

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

Pros of paper-onboarding

  • Focused specifically on onboarding UI, providing a polished and tailored solution
  • Lightweight and easy to integrate into existing projects
  • Customizable with various animation options and styles

Cons of paper-onboarding

  • Limited to onboarding functionality, less versatile than Spring
  • Fewer stars and contributors, potentially indicating less community support
  • May require additional libraries for more complex animations or interactions

Code Comparison

Spring:

let animation = CABasicAnimation(keyPath: "position.y")
animation.fromValue = view.layer.position.y
animation.toValue = view.layer.position.y - 50
animation.duration = 0.5
animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
view.layer.add(animation, forKey: nil)

paper-onboarding:

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

Spring offers more flexibility for general animations, while paper-onboarding provides a streamlined API specifically for onboarding flows. Spring requires more code for custom animations, whereas paper-onboarding simplifies the process for its specific use case.

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

Pros of folding-cell

  • Specialized for creating folding cell animations in iOS
  • Provides a unique and visually appealing UI component
  • Easier to implement specific folding cell animations

Cons of folding-cell

  • Limited to iOS platform, while Spring supports both iOS and macOS
  • Focused on a single UI component, whereas Spring offers a broader range of animations
  • Less actively maintained compared to Spring

Code Comparison

folding-cell:

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

cell.foregroundView = foregroundView
cell.containerView = containerView

Spring:

let animation = Spring(duration: 0.7, animations: {
    view.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
})
animation.spring = .interactiveSpring
animation.animate()

Both libraries offer easy-to-use APIs for creating animations, but folding-cell is more specialized for its specific use case, while Spring provides a more general-purpose animation framework.

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

Pros of expanding-collection

  • Specialized for creating expanding card animations
  • Provides a more visually appealing and interactive UI for collection views
  • Easier to implement complex card animations with less custom code

Cons of expanding-collection

  • Limited to a specific use case (expanding card collections)
  • Less versatile compared to Spring's general-purpose animation framework
  • Steeper learning curve for developers not familiar with custom collection view layouts

Code Comparison

expanding-collection:

let expandingCollection = ExpandingCollection(collectionViewLayout: CustomCollectionViewLayout())
expandingCollection.collectionView?.register(DemoCell.self, forCellWithReuseIdentifier: String(describing: DemoCell.self))

Spring:

Spring.animate(.pop) {
    view.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
} completion: {
    view.transform = .identity
}

Summary

expanding-collection is a specialized library for creating expanding card animations in collection views, offering a visually appealing UI with less custom code. However, it's limited to this specific use case and may have a steeper learning curve. Spring, on the other hand, is a more versatile animation framework that can be applied to various UI elements, but may require more custom code for complex card animations.

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

Updated for Swift 4.2

Requires Xcode 10 and Swift 4.2.

Installation

Drop in the Spring folder to your Xcode project (make sure to enable "Copy items if needed" and "Create groups").

Or via CocoaPods:

use_frameworks!
pod 'Spring', :git => 'https://github.com/MengTo/Spring.git'

Usage with Storyboard

In Identity Inspector, connect the UIView to SpringView Class and set the animation properties in Attribute Inspector.

Usage with Code

layer.animation = "squeezeDown"
layer.animate()

Demo The Animations

Chaining Animations

layer.y = -50
animateToNext {
  layer.animation = "fall"
  layer.animateTo()
}

Functions

animate()
animateNext { ... }
animateTo()
animateToNext { ... }

Animation

shake
pop
morph
squeeze
wobble
swing
flipX
flipY
fall
squeezeLeft
squeezeRight
squeezeDown
squeezeUp
slideLeft
slideRight
slideDown
slideUp
fadeIn
fadeOut
fadeInLeft
fadeInRight
fadeInDown
fadeInUp
zoomIn
zoomOut
flash

Curve

spring
linear
easeIn
easeOut
easeInOut

Properties

force
duration
delay
damping
velocity
repeatCount
scale
x
y
rotate

* Not all properties work together. Play with the demo app.

Autostart

Allows you to animate without code. Don't need to use this if you plan to start the animation in code.

Autohide

Saves you the hassle of adding a line "layer.alpha = 0" in viewDidLoad().

Known issue

Animations won't autostart when view is reached via performSegueWithIdentifier.

Tutorials

ChangeLog

License

Spring is released under the MIT license. See LICENSE for details.