All Projects → DarthMike → Swiftanimations

DarthMike / Swiftanimations

Licence: mit
A small DSL to chain animations on top of UIKit

Programming Languages

swift
15916 projects
dsl
153 projects

Projects that are alternatives of or similar to Swiftanimations

Inputbaraccessoryview
A simple and easily customizable InputAccessoryView for making powerful input bars with autocomplete and attachments
Stars: ✭ 807 (+2503.23%)
Mutual labels:  uikit
Vtacknowledgementsviewcontroller
Acknowledgements screen displaying a list of licenses, for example from CocoaPods dependencies.
Stars: ✭ 863 (+2683.87%)
Mutual labels:  uikit
Viewcomposer
Compose views using enums swiftly: `let label: UILabel = [.text("Hello"), .textColor(.red)]`
Stars: ✭ 27 (-12.9%)
Mutual labels:  uikit
Bfkit
BFKit is a collection of useful classes and categories to develop Apps faster.
Stars: ✭ 811 (+2516.13%)
Mutual labels:  uikit
Wwdc20playground
WWDC20 Swift Student Challenge Winner (Actually a WWDC 19 project but reworked & rebranded)
Stars: ✭ 27 (-12.9%)
Mutual labels:  uikit
Zircleui
🚀 zircle-ui is a frontend library to develop zoomable user interfaces.
Stars: ✭ 870 (+2706.45%)
Mutual labels:  uikit
Overlaycontainer
Non-intrusive iOS UI library to implement overlay based interfaces
Stars: ✭ 777 (+2406.45%)
Mutual labels:  uikit
Quick Free Bootstrap Theme
Free Bootstrap 4 Theme perfect for building responsive, mobile-first projects on the web suitable for businesses, startups, and agencies.
Stars: ✭ 31 (+0%)
Mutual labels:  uikit
Objc Uti
Objective-C wrapper for Uniform Type Identifiers (UTIs)
Stars: ✭ 7 (-77.42%)
Mutual labels:  uikit
Qmuidemo ios
Sample Code for QMUI iOS
Stars: ✭ 912 (+2841.94%)
Mutual labels:  uikit
Verticalcardswiper
A marriage between the Shazam Discover UI and Tinder, built with UICollectionView in Swift.
Stars: ✭ 830 (+2577.42%)
Mutual labels:  uikit
Gopherjs Electron
Gopherjs bindings for Electron with an API translator.
Stars: ✭ 26 (-16.13%)
Mutual labels:  uikit
Tkswitchercollection
An animation switch collection
Stars: ✭ 877 (+2729.03%)
Mutual labels:  uikit
Statusalert
Display Apple system-like self-hiding status alerts. It is well suited for notifying user without interrupting user flow in iOS-like way.
Stars: ✭ 809 (+2509.68%)
Mutual labels:  uikit
Collectionviewpaginglayout
a simple but highly customizable paging layout for UICollectionView.
Stars: ✭ 947 (+2954.84%)
Mutual labels:  uikit
Cyltabbarcontroller
[EN]It is an iOS UI module library for adding animation to iOS tabbar items and icons with Lottie, and adding a bigger center UITabBar Item. [CN]【中国特色 TabBar】一行代码实现 Lottie 动画TabBar,支持中间带+号的TabBar样式,自带红点角标,支持动态刷新。【iOS13 & Dark Mode & iPhone XS MAX supported】
Stars: ✭ 6,605 (+21206.45%)
Mutual labels:  uikit
Giu
Cross platform rapid GUI framework for golang based on Dear ImGui.
Stars: ✭ 862 (+2680.65%)
Mutual labels:  uikit
Data Driven Vc
Swift Data-Driven UI examples
Stars: ✭ 31 (+0%)
Mutual labels:  uikit
C4ios
C4 is an open-source creative coding framework that harnesses the power of native iOS programming with a simplified API that gets you working with media right away. Build artworks, design interfaces and explore new possibilities working with media and interaction.
Stars: ✭ 952 (+2970.97%)
Mutual labels:  uikit
Weekdayssegmentedcontrol
A Custom segmented control to select weekdays for iOS
Stars: ✭ 14 (-54.84%)
Mutual labels:  uikit

Build Status Carthage compatible

Pod Platform Pod License

codebeat badge cocoapods-doc Readme Score

SwiftAnimations

SwiftAnimations is a small DSL to chain of animations on top of UIKit, unify animation parameters across all application and simplify even more your animation code.

Features

  • Chain simple animations with less and more concise code
  • Sensible default values, so you don't repeat information across all animation blocks
  • Opt in to configure whatever values you see fit on every animation, as opposed to declaring (and repeating) whole list of parameters for every one
  • Default values can be configured for all animations across all application. Change only the values that are different for the specific animation
  • Support for spring and standard animations

Chaining animations

Turn complex sequences of animations into simple cascade and easy to read code:

// Start with a call to 'animate'
animate {
  self.red.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
}.thenAnimate {   // Chain animations, to be executed in order
  self.green.transform = CGAffineTransformMakeRotation(-CGFloat(M_PI_2))
}.afterDelay(1)
 .thenAnimate {
  self.blue.transform = CGAffineTransformMakeScale(1.5, 1)
}.withOptions(.CurveEaseOut).thenAnimate {
  self.yellow.transform = CGAffineTransformMakeScale(1, 1.5)
}.withOptions(.CurveEaseOut).thenAnimate {
  let scale = CGAffineTransformMakeScale(0.5, 0.5)
  self.red.transform = scale
  self.green.transform = scale
  self.blue.transform = scale
  self.yellow.transform = scale
}.completion { completed in
 // Completion of all animations
  println("Completed!")
}

Unified animation values and default values

SwiftAnimations configures all animations with default values for duration, curve, and spring damping and velocity. You can change this globally or per-animation.

// All animations in my app have a baseline of 0.35. I rarely change this
setDefaultAnimationDuration(0.35)
// All animations in my app by default EaseIn EaseOut.
setDefaultAnimationCurve(.EaseInOut)

Also by default animations are 'standard', not spring animations. You can make all animations change the system call they use by switching a simple configuration value:

// I want unified look across application, and I will be using spring animations everywhere unless otherwise specified
setDefaultAnimationType(.Spring)
// Moreover, tedious repetition removed by specifying a default value for damping and velocity
setDefaultSpringDamping(0.1)
setDefaultInitialVelocity(0.3)

If you don't specify default values, the library will use the default ones.

Per-animation parameters

You can also change specific values per-animation:

animate {
  // Animation 1
}.withOptions(.CurveEaseOut).withDuration(0.5).thenAnimate {   // Modify how 'previous' animation is performed
  // Animation 2
}.withDuration(0.1).withType(.Spring).thenAnimate {
  // Animation 3
}.withType(.Regular)
 .afterDelay(0.2)

Roadmap

Later I will be adding redefined animations. And maybe a way to configure those as well across all application code.

animate(flip(self.avatarView))
.thenAnimate(bounce(self.button)).start()

Suggestions and pull requests welcome :)

Why?

UIKit animations API is designed to be simple. It does it job very well for fire-and-forget animations. But there are some times where the application demands not so simple animations.

There are often times when two or three animations need to be chained to achieved desired visual effects. Generally this can be easily done by nesting UIKit.animateWithDuration(...) calls, like so:

UIView.animateWithDuration(0.3, animations: {
  //AnimationA
}, completion: {
  UIView.animateWithDuration(0.3, animations: {
    //AnimationB
  }, completion: {
    UIView.animateWithDuration(0.3, animations: {
      //AnimationC
    }, completion: {
      UIView.animateWithDuration(0.3, animations: {
        //AnimationD
      }, completion: {
        //Usual cleanup
      })
    })
  })
})

Imagine how this thing looks in Objective-C.

There is a big problem with this approach, and it is readability. Swift can make it a bit less painful if you abstract the animations into inner functions of the current function, but I would say that it is very ugly code. And I believe that animation and UI code should be crystal clear, so you don't have to run everything to see what will move around, and where.

See more in the article I wrote

Installation

##CocoaPods Add the pod to your Podfile. Being a Swift-only library, it is required to be linked as a framework (dynamic library).

use_frameworks!
pod 'SwiftAnimations'

Carthage

Add the repository to your Cartfile.

github "DarthMike/SwiftAnimations"

Then drag and drop the produced SwiftAnimations.framework from Carthage/build

Manual

Just drop into your project the files under Source directory.

Author

Miguel Angel Quiñones / @miguelquinon

Inspiration

This idea took off from working in my current project using Swift, and after seeing Spring

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].