All Projects → mathewsanders → Scrubber

mathewsanders / Scrubber

Licence: mit
🎚Swift playground for building animations with UIViewPropertyAnimator

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Scrubber

Awesome Swift Playgrounds
A List of Awesome Swift Playgrounds
Stars: ✭ 3,521 (+10903.13%)
Mutual labels:  playground
Unityplayground
A collection of simple scripts to create 2D physics game, intended for giving workshops to a young audience
Stars: ✭ 603 (+1784.38%)
Mutual labels:  playground
Electron Playground
This is a project to quickly experiment and learn electron related APIs
Stars: ✭ 938 (+2831.25%)
Mutual labels:  playground
Go Playground
Better Go Playground powered by React and Monaco editor
Stars: ✭ 354 (+1006.25%)
Mutual labels:  playground
React View
React View is an interactive playground, documentation and code generator for your components.
Stars: ✭ 544 (+1600%)
Mutual labels:  playground
Whats New In Swift 5 0
An Xcode playground that demonstrates the new features introduced in Swift 5.0.
Stars: ✭ 703 (+2096.88%)
Mutual labels:  playground
Playgroundtdd
Small library to easily run your tests directly within a Playground
Stars: ✭ 319 (+896.88%)
Mutual labels:  playground
Flutterplayground
Playground app for Flutter
Stars: ✭ 859 (+2584.38%)
Mutual labels:  playground
Graphql Editor
📺 Visual Editor & GraphQL IDE. Draw GraphQL schemas using visual 🔷 nodes and explore GraphQL API with beautiful UI. Even 🐒 can do that!
Stars: ✭ 5,485 (+17040.63%)
Mutual labels:  playground
Deer Executor
An executor for online judge —— 基于Go语言实现的代码评测工具
Stars: ✭ 23 (-28.12%)
Mutual labels:  playground
Playground
Instantly create Swift playgrounds from the command line
Stars: ✭ 391 (+1121.88%)
Mutual labels:  playground
Playalways
Create Xcode playgrounds from your menu bar
Stars: ✭ 515 (+1509.38%)
Mutual labels:  playground
Flexibleimage
A simple way to play with the image!
Stars: ✭ 798 (+2393.75%)
Mutual labels:  playground
Luaviewsdk
A cross-platform framework to build native, dynamic and swift user interface - 强大轻巧灵活的客户端动态化解决方案
Stars: ✭ 3,586 (+11106.25%)
Mutual labels:  playground
Vuep
🎡 A component for rendering Vue components with live editor and preview.
Stars: ✭ 840 (+2525%)
Mutual labels:  playground
Uistackviewplayground
Playground to play with UIStackViews.
Stars: ✭ 319 (+896.88%)
Mutual labels:  playground
Flutterbasicwidgets
ABC of Flutter widgets. Intended for super beginners at Flutter. Play with 35+ examples in DartPad directly and get familiar with various basic widgets in Flutter
Stars: ✭ 609 (+1803.13%)
Mutual labels:  playground
Revery Playground
Live, interactive playground for Revery examples
Stars: ✭ 14 (-56.25%)
Mutual labels:  playground
Awesome Ai Books
Some awesome AI related books and pdfs for learning and downloading, also apply some playground models for learning
Stars: ✭ 855 (+2571.88%)
Mutual labels:  playground
Ngx Formly Playground
Project with list of Angular Formly exercises. Every next exercise add new feature to the previous one.
Stars: ✭ 16 (-50%)
Mutual labels:  playground

Playground Animation Scrubber 🎚

There are a lot of frameworks and tools for making animations and animated transitions for your iOS projects.

If you're targeting iOS/tvOS 10.0+, then UIViewPropertyAnimator is probably powerful enough for your needs: It includes the standard easing curves, a nice implementation of spring physics, an easy way to define your own custom timing curve, and a scalable API that allows from simple single step interpolation, to chained, interruptible, and animations that can be modified on the fly.

ScrubContainerView

This project doesn't modify or build on top of UIViewPropertyAnimator, but instead provides ScrubContainerView, a simple UIView subclass, that makes it easier to create, explore, debug, and refine an animation in a playground.

  1. Start by making a playground and importing UIKit and PlaygroundSupport
import UIKit
import PlaygroundSupport
  1. Create a new ScrubContainerView and make that the playground's liveView (this presents the view in the playground's assistant editor panel.
let container = ScrubContainerView()
PlaygroundPage.current.liveView = container
  1. Next, go ahead an set up the objects to be animated, adding them to the stage view of ScrubContainerView and setting their initial positions.
let square = UIView()
container.stage.addSubview(square)
square.center = container.stage.center
square.transform = .identity
square.bounds.size = CGSize(width: 150, height: 50)
square.backgroundColor = .red
  1. Finally, assign animator with a closure that returns a UIViewPropertyAnimator. This defines the animations to perform.
container.animator = {

    // create the animator with the duration and timing curve
    // (in this case using a spring-physics)
    let animator = UIViewPropertyAnimator(duration: 2.0, dampingRatio: 0.5)

    // define the properties to animate
    animator.addAnimations {
        square.transform = CGAffineTransform(rotationAngle: CGFloat.pi/2)
        square.bounds.size = CGSize(width: 50, height: 150)
        square.backgroundColor = .blue
    }
    // return the animator
    return animator
}

ScrubContainerView adds a UISlider that lets you scrub through the animation and look at it at any intermediate step.

An option for step #3 is to wrap the expressions that define the stating state into the startState closure:

container.startState = {
    square.transform = .identity
    square.bounds.size = CGSize(width: 150, height: 50)
    square.backgroundColor = .red
}

If this property is defined ScrubContainerView will add a button button that lets you to watch the animation perform with it's defined duration and timing curve:

Initializers

A ScrubContainerView can be initialized multiple ways. The default initializer creates a stage width a 300x300 pixel size.

ScrubContainerView.init(width: Double, height: Double) allows a stage of any size.

Convenience initializers ScrubContainerView.init(device: Device) and ScrubContainerView.init(device: Device, orientation: Orientation) allow for stages to be created for Device.iPhoneSE, .iPhone, and .iPhonePlus and orientations .portrait or .landscape.

Examples

The playground includes the example above, as well as a slightly more complex example that includes a 4-step animation chained together using keyframes to show how more complex multi-step animations can be built, and a blank template ready to start writing a new animation from scratch.

Roadmap

  • [x] UISlider to scrub animations
  • [x] Button to play animation with default timing curve and duration
  • [x] Initializers for different device sizes
  • [ ] Resume animation after scrubbing
  • [ ] Pause/resume animation
  • [ ] Scrub paused animation

Requirements

  • Swift 3.0
  • iOS/tvOS 10.0+

Author

Made with ❤️ by @permakittens

Contributing

Feedback, or contributions for bug fixing or improvements are welcome. Feel free to submit a pull request or open an issue.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].