cats-oss/Sica

🦌 Simple Interface Core Animation. Run type-safe animation sequencially or parallelly

Swift

1,047

25 commits

updated Nov 30, 2021

See the code

README

Simple Interface Core Animation

Sica

Platform Language Carthage
Swift Package Manager Version License

Sica can execute various animations sequentially or parallelly.

Features

  • Animation with duration and delay
  • parallel / sequence animation
  • Easings
  • Springs
  • Transition

Requirements

  • Xcode 9.3 or greater
  • iOS 9 or greater
  • tvOS 10.0 or greater
  • macOS 10.11 or greater
  • Swift 4.2 (since 0.3.4)

Installation

Carthage

If you’re using Carthage, simply add Sica to your Cartfile:

github "cats-oss/Sica"

CocoaPods

Sica is available through CocoaPods. To instal it, simply add the following line to your Podfile:

pod 'Sica'

Swift Package Manager

Sica is available through SwiftPM, create Package.swift and add dependencies value

dependencies: [
    .package(url: "https://github.com/cats-oss/Sica.git", from: "0.4.1")
]

See also: GitHub - j-channings/swift-package-manager-ios: Example of how to use SPM v4 to manage iOS dependencies

Usage

Sample Animation

Sequence Animation

If you set .sequence, sequence animation is shown.

let animator = Animator(view: sampleView)
animator
    .addBasicAnimation(keyPath: .positionX, from: 50, to: 150, duration: 2, timingFunction: .easeOutExpo)
    .addSpringAnimation(keyPath: .boundsSize, from: sampleView.frame.size, to: CGSize(width: 240, height: 240), damping: 12, mass: 1, stiffness: 240, initialVelocity: 0, duration: 1)
    .run(type: .sequence)

SequenceAnimation

Parallel Animation

If you set .parallel, parallel animation is shown.

let animator = Animator(view: sampleView)
animator
    .addBasicAnimation(keyPath: .positionX, from: 50, to: 150, duration: 5, timingFunction: .easeOutExpo)
    .addBasicAnimation(keyPath: .transformRotationZ, from: 0, to: CGFloat.pi, duration: 3, timingFunction: .easeOutExpo)
    .run(type: .parallel)

ParallelAnimation

Forever Animation

If you set forever before calling run, forever animation is shown.

let animator = Animator(view: sampleView)
animator
    .addBasicAnimation(keyPath: .positionX, from: 50, to: 150, duration: 2, timingFunction: .easeOutExpo)
    .addBasicAnimation(keyPath: .positionX, from: 150, to: 50, duration: 2, timingFunction: .easeOutExpo)
    .forever(autoreverses: false)
    .run(type: .sequence)

Forever

Cancel

If you want to cancel animation, you should call cancel.

let animator = Animator(view: sampleView)
/*
Add animation and run
*/
animator.cancel() // Animation cancel

Remove Added Animations

If you call run and then you call add animation method, no animation will be added. If you use animator again, you call removeAll before addBasicAnimation or addSpringAnimation or addTransitionAnimation.

let animator = Animator(view: sampleView)
/*
Add animation and run
*/

// Bad
animator.addBasicAnimation() // 🙅 you can't add animation

// Good
animator.removeAll()
        .addBasicAnimation() // 🙆 You can add animation.

Functions

Add Animation

    public func addBasicAnimation<T>(keyPath: Sica.AnimationKeyPath<T>, from: T, to: T, duration: Double, delay: Double = default, timingFunction: Sica.TimingFunction = default) -> Self where T : AnimationValueType
    public func addSpringAnimation<T>(keyPath: Sica.AnimationKeyPath<T>, from: T, to: T, damping: CGFloat, mass: CGFloat, stiffness: CGFloat, initialVelocity: CGFloat, duration: Double, delay: Double = default, timingFunction: Sica.TimingFunction = default) -> Self where T : AnimationValueType
    public func addTransitionAnimation(startProgress: Float, endProgress: Float, type: Sica.Transition, subtype: Sica.TransitionSub, duration: Double, delay: Double = default, timingFunction: Sica.TimingFunction = default) -> Self

Add Animation Option

    public func delay(_ delay: Double) -> Self
    public func forever(autoreverses: Bool = default) -> Self

Animation Operation

    public func run(type: Sica.Animator.AnimationPlayType, isRemovedOnCompletion: Bool = default, completion: (() -> Swift.Void)? = default)
    public func cancel()
    public func removeAll() -> Self

Extensions

You can access sica property in UIView and CALayer.

let view = UIView(frame: ...)
view.sica
    .addBasicAnimation(keyPath: .positionX, from: 50, to: 150, duration: 2, timingFunction: .easeOutExpo)
    .run(type: .sequence)
let layer = CALayer()
layer.sica
    .addBasicAnimation(keyPath: .positionX, from: 50, to: 150, duration: 2, timingFunction: .easeOutExpo)
    .run(type: .sequence)

Support

Animation

  • CABasicAnimation
  • CATransition
  • CASpringAnimation

AnimationPlayType

you can choose animation play type

  • run animation sequentially
  • run animation parallelly

EasingFunctions

you can choose various timing functions

EasingFunctions

KeyPaths Table

SicaKeyPath
.anchorPointanchorPoint
.backgroundColorbackgroundColor
.borderColorborderColor
.borderWidthborderWidth
.boundsbounds
.contentscontents
.contentsRectcontentsRect
.cornerRadiuscornerRadius
.filtersfilters
.frameframe
.hiddenhidden
.maskmask
.masksToBoundsmasksToBounds
.opacityopacity
.pathpath
.positionposition
.shadowColorshadowColor
.shadowOffsetshadowOffset
.shadowOpacityshadowOpacity
.shadowPathshadowPath
.shadowRadiusshadowRadius
.sublayerssublayers
.sublayerTransformsublayerTransform
.transformtransform
.zPositionzPosition

Anchor Point

SicaKeyPath
.anchorPointXanchorPoint.x
.anchorPointyanchorPoint.y

Bounds

SicaKeyPath
.boundsOriginbounds.origin
.boundsOriginXbounds.origin.x
.boundsOriginYbounds.origin.y
.boundsSizebounds.size
.boundsSizeWidthbounds.size.width
.boundsSizeHeightbounds.size.height

Contents

SicaKeyPath
.contentsRectOrigincontentsRect.origin
.contentsRectOriginXcontentsRect.origin.x
.contentsRectOriginYcontentsRect.origin.y
.contentsRectSizecontentsRect.size
.contentsRectSizeWidthcontentsRect.size.width
.contentsRectSizeHeightcontentsRect.size.height

Frame

SicaKeyPath
.frameOriginframe.origin
.frameOriginXframe.origin.x
.frameOriginYframe.origin.y
.frameSizeframe.size
.frameSizeWidthframe.size.width
.frameSizeHeightframe.size.height

Position

SicaKeyPath
.positionXposition.x
.positionYposition.y

Shadow Offset

SicaKeyPath
.shadowOffsetWidthshadowOffset.width
.shadowOffsetHeightshadowOffset.height

Sublayer Transform

SicaKeyPath
.sublayerTransformRotationXsublayerTransform.rotation.x
.sublayerTransformRotationYsublayerTransform.rotation.y
.sublayerTransformRotationZsublayerTransform.rotation.z
.sublayerTransformScaleXsublayerTransform.scale.x
.sublayerTransformScaleYsublayerTransform.scale.y
.sublayerTransformScaleZsublayerTransform.scale.z
.sublayerTransformTranslationXsublayerTransform.translation.x
.sublayerTransformTranslationYsublayerTransform.translation.y
.sublayerTransformTranslationZsublayerTransform.translation.z

Transform

SicaKeyPath
.transformRotationXtransform.rotation.x
.transformRotationYtransform.rotation.y
.transformRotationZtransform.rotation.z
.transformScaleXtransform.scale.x
.transformScaleYtransform.scale.y
.transformScaleZtransform.scale.z
.transformTranslationXtransform.translation.x
.transformTranslationYtransform.translation.y
.transformTranslationZtransform.translation.z

License

Sica is available under the MIT license. See the LICENSE file for more info.

animation
carthage
cocoapods
ios
macos
swift
swift-package-manager
tvos

cats-oss/Sica

🦌 Simple Interface Core Animation. Run type-safe animation sequencially or parallelly

Swift

1,047

25 commits

updated Nov 30, 2021

See the code

README

Simple Interface Core Animation

Sica

Platform Language Carthage
Swift Package Manager Version License

Sica can execute various animations sequentially or parallelly.

Features

  • Animation with duration and delay
  • parallel / sequence animation
  • Easings
  • Springs
  • Transition

Requirements

  • Xcode 9.3 or greater
  • iOS 9 or greater
  • tvOS 10.0 or greater
  • macOS 10.11 or greater
  • Swift 4.2 (since 0.3.4)

Installation

Carthage

If you’re using Carthage, simply add Sica to your Cartfile:

github "cats-oss/Sica"

CocoaPods

Sica is available through CocoaPods. To instal it, simply add the following line to your Podfile:

pod 'Sica'

Swift Package Manager

Sica is available through SwiftPM, create Package.swift and add dependencies value

dependencies: [
    .package(url: "https://github.com/cats-oss/Sica.git", from: "0.4.1")
]

See also: GitHub - j-channings/swift-package-manager-ios: Example of how to use SPM v4 to manage iOS dependencies

Usage

Sample Animation

Sequence Animation

If you set .sequence, sequence animation is shown.

let animator = Animator(view: sampleView)
animator
    .addBasicAnimation(keyPath: .positionX, from: 50, to: 150, duration: 2, timingFunction: .easeOutExpo)
    .addSpringAnimation(keyPath: .boundsSize, from: sampleView.frame.size, to: CGSize(width: 240, height: 240), damping: 12, mass: 1, stiffness: 240, initialVelocity: 0, duration: 1)
    .run(type: .sequence)

SequenceAnimation

Parallel Animation

If you set .parallel, parallel animation is shown.

let animator = Animator(view: sampleView)
animator
    .addBasicAnimation(keyPath: .positionX, from: 50, to: 150, duration: 5, timingFunction: .easeOutExpo)
    .addBasicAnimation(keyPath: .transformRotationZ, from: 0, to: CGFloat.pi, duration: 3, timingFunction: .easeOutExpo)
    .run(type: .parallel)

ParallelAnimation

Forever Animation

If you set forever before calling run, forever animation is shown.

let animator = Animator(view: sampleView)
animator
    .addBasicAnimation(keyPath: .positionX, from: 50, to: 150, duration: 2, timingFunction: .easeOutExpo)
    .addBasicAnimation(keyPath: .positionX, from: 150, to: 50, duration: 2, timingFunction: .easeOutExpo)
    .forever(autoreverses: false)
    .run(type: .sequence)

Forever

Cancel

If you want to cancel animation, you should call cancel.

let animator = Animator(view: sampleView)
/*
Add animation and run
*/
animator.cancel() // Animation cancel

Remove Added Animations

If you call run and then you call add animation method, no animation will be added. If you use animator again, you call removeAll before addBasicAnimation or addSpringAnimation or addTransitionAnimation.

let animator = Animator(view: sampleView)
/*
Add animation and run
*/

// Bad
animator.addBasicAnimation() // 🙅 you can't add animation

// Good
animator.removeAll()
        .addBasicAnimation() // 🙆 You can add animation.

Functions

Add Animation

    public func addBasicAnimation<T>(keyPath: Sica.AnimationKeyPath<T>, from: T, to: T, duration: Double, delay: Double = default, timingFunction: Sica.TimingFunction = default) -> Self where T : AnimationValueType
    public func addSpringAnimation<T>(keyPath: Sica.AnimationKeyPath<T>, from: T, to: T, damping: CGFloat, mass: CGFloat, stiffness: CGFloat, initialVelocity: CGFloat, duration: Double, delay: Double = default, timingFunction: Sica.TimingFunction = default) -> Self where T : AnimationValueType
    public func addTransitionAnimation(startProgress: Float, endProgress: Float, type: Sica.Transition, subtype: Sica.TransitionSub, duration: Double, delay: Double = default, timingFunction: Sica.TimingFunction = default) -> Self

Add Animation Option

    public func delay(_ delay: Double) -> Self
    public func forever(autoreverses: Bool = default) -> Self

Animation Operation

    public func run(type: Sica.Animator.AnimationPlayType, isRemovedOnCompletion: Bool = default, completion: (() -> Swift.Void)? = default)
    public func cancel()
    public func removeAll() -> Self

Extensions

You can access sica property in UIView and CALayer.

let view = UIView(frame: ...)
view.sica
    .addBasicAnimation(keyPath: .positionX, from: 50, to: 150, duration: 2, timingFunction: .easeOutExpo)
    .run(type: .sequence)
let layer = CALayer()
layer.sica
    .addBasicAnimation(keyPath: .positionX, from: 50, to: 150, duration: 2, timingFunction: .easeOutExpo)
    .run(type: .sequence)

Support

Animation

  • CABasicAnimation
  • CATransition
  • CASpringAnimation

AnimationPlayType

you can choose animation play type

  • run animation sequentially
  • run animation parallelly

EasingFunctions

you can choose various timing functions

EasingFunctions

KeyPaths Table

SicaKeyPath
.anchorPointanchorPoint
.backgroundColorbackgroundColor
.borderColorborderColor
.borderWidthborderWidth
.boundsbounds
.contentscontents
.contentsRectcontentsRect
.cornerRadiuscornerRadius
.filtersfilters
.frameframe
.hiddenhidden
.maskmask
.masksToBoundsmasksToBounds
.opacityopacity
.pathpath
.positionposition
.shadowColorshadowColor
.shadowOffsetshadowOffset
.shadowOpacityshadowOpacity
.shadowPathshadowPath
.shadowRadiusshadowRadius
.sublayerssublayers
.sublayerTransformsublayerTransform
.transformtransform
.zPositionzPosition

Anchor Point

SicaKeyPath
.anchorPointXanchorPoint.x
.anchorPointyanchorPoint.y

Bounds

SicaKeyPath
.boundsOriginbounds.origin
.boundsOriginXbounds.origin.x
.boundsOriginYbounds.origin.y
.boundsSizebounds.size
.boundsSizeWidthbounds.size.width
.boundsSizeHeightbounds.size.height

Contents

SicaKeyPath
.contentsRectOrigincontentsRect.origin
.contentsRectOriginXcontentsRect.origin.x
.contentsRectOriginYcontentsRect.origin.y
.contentsRectSizecontentsRect.size
.contentsRectSizeWidthcontentsRect.size.width
.contentsRectSizeHeightcontentsRect.size.height

Frame

SicaKeyPath
.frameOriginframe.origin
.frameOriginXframe.origin.x
.frameOriginYframe.origin.y
.frameSizeframe.size
.frameSizeWidthframe.size.width
.frameSizeHeightframe.size.height

Position

SicaKeyPath
.positionXposition.x
.positionYposition.y

Shadow Offset

SicaKeyPath
.shadowOffsetWidthshadowOffset.width
.shadowOffsetHeightshadowOffset.height

Sublayer Transform

SicaKeyPath
.sublayerTransformRotationXsublayerTransform.rotation.x
.sublayerTransformRotationYsublayerTransform.rotation.y
.sublayerTransformRotationZsublayerTransform.rotation.z
.sublayerTransformScaleXsublayerTransform.scale.x
.sublayerTransformScaleYsublayerTransform.scale.y
.sublayerTransformScaleZsublayerTransform.scale.z
.sublayerTransformTranslationXsublayerTransform.translation.x
.sublayerTransformTranslationYsublayerTransform.translation.y
.sublayerTransformTranslationZsublayerTransform.translation.z

Transform

SicaKeyPath
.transformRotationXtransform.rotation.x
.transformRotationYtransform.rotation.y
.transformRotationZtransform.rotation.z
.transformScaleXtransform.scale.x
.transformScaleYtransform.scale.y
.transformScaleZtransform.scale.z
.transformTranslationXtransform.translation.x
.transformTranslationYtransform.translation.y
.transformTranslationZtransform.translation.z

License

Sica is available under the MIT license. See the LICENSE file for more info.

animation
carthage
cocoapods
ios
macos
swift
swift-package-manager
tvos

Significant stargazers

Max Howell

7,875 followers · starred Jul 2018

Alejandro Isaza

229 followers · starred Jul 2018

Yonat Sharon

102 followers · starred Jun 2020

Syed Mohd Gulam Baquer

129 followers · starred Jul 2018