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

Overview

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, from: T, to: T, duration: Double, delay: Double = default, timingFunction: Sica.TimingFunction = default) -> Self where T : AnimationValueType
    public func addSpringAnimation<T>(keyPath: Sica.AnimationKeyPath, 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

Sica KeyPath
.anchorPoint anchorPoint
.backgroundColor backgroundColor
.borderColor borderColor
.borderWidth borderWidth
.bounds bounds
.contents contents
.contentsRect contentsRect
.cornerRadius cornerRadius
.filters filters
.frame frame
.hidden hidden
.mask mask
.masksToBounds masksToBounds
.opacity opacity
.path path
.position position
.shadowColor shadowColor
.shadowOffset shadowOffset
.shadowOpacity shadowOpacity
.shadowPath shadowPath
.shadowRadius shadowRadius
.sublayers sublayers
.sublayerTransform sublayerTransform
.transform transform
.zPosition zPosition

Anchor Point

Sica KeyPath
.anchorPointX anchorPoint.x
.anchorPointy anchorPoint.y

Bounds

Sica KeyPath
.boundsOrigin bounds.origin
.boundsOriginX bounds.origin.x
.boundsOriginY bounds.origin.y
.boundsSize bounds.size
.boundsSizeWidth bounds.size.width
.boundsSizeHeight bounds.size.height

Contents

Sica KeyPath
.contentsRectOrigin contentsRect.origin
.contentsRectOriginX contentsRect.origin.x
.contentsRectOriginY contentsRect.origin.y
.contentsRectSize contentsRect.size
.contentsRectSizeWidth contentsRect.size.width
.contentsRectSizeHeight contentsRect.size.height

Frame

Sica KeyPath
.frameOrigin frame.origin
.frameOriginX frame.origin.x
.frameOriginY frame.origin.y
.frameSize frame.size
.frameSizeWidth frame.size.width
.frameSizeHeight frame.size.height

Position

Sica KeyPath
.positionX position.x
.positionY position.y

Shadow Offset

Sica KeyPath
.shadowOffsetWidth shadowOffset.width
.shadowOffsetHeight shadowOffset.height

Sublayer Transform

Sica KeyPath
.sublayerTransformRotationX sublayerTransform.rotation.x
.sublayerTransformRotationY sublayerTransform.rotation.y
.sublayerTransformRotationZ sublayerTransform.rotation.z
.sublayerTransformScaleX sublayerTransform.scale.x
.sublayerTransformScaleY sublayerTransform.scale.y
.sublayerTransformScaleZ sublayerTransform.scale.z
.sublayerTransformTranslationX sublayerTransform.translation.x
.sublayerTransformTranslationY sublayerTransform.translation.y
.sublayerTransformTranslationZ sublayerTransform.translation.z

Transform

Sica KeyPath
.transformRotationX transform.rotation.x
.transformRotationY transform.rotation.y
.transformRotationZ transform.rotation.z
.transformScaleX transform.scale.x
.transformScaleY transform.scale.y
.transformScaleZ transform.scale.z
.transformTranslationX transform.translation.x
.transformTranslationY transform.translation.y
.transformTranslationZ transform.translation.z

License

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

You might also like...
Get a remote image's size and type without downloading the full image

FastImage FastImage 2.0 is an Swift port of the Ruby project by Stephen Sykes. It's directive is to request as little data as possible (usually just t

WordleDemo - A SwiftUI implementation of Wordle's core logic and UI
WordleDemo - A SwiftUI implementation of Wordle's core logic and UI

WordleDemo Just a SwiftUI implementation of Wordle's core logic and UI Contains

Simple water drops animation 💧
Simple water drops animation 💧

WaterDrops Simple water drops animation 💧 Example override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = U

A simple spritesheet animation system for Raylib on Swift.
A simple spritesheet animation system for Raylib on Swift.

About A simple spritesheet animation system for Raylib on Swift. Aeni allows you to quickly and easily animate your spritesheet in your Raylib for Swi

TTouchAnimatedButton is a simple and flexible animation component fully written in Swift
TTouchAnimatedButton is a simple and flexible animation component fully written in Swift

TTouchAnimatedButton is a simple and flexible animation component fully written in Swift. TTouchAnimatedButton is developed to make user feel button click becomes more vivid and realistic.

ChainPageCollectionView  A custom View with two level chained collection views and fancy transition animation
ChainPageCollectionView A custom View with two level chained collection views and fancy transition animation

ChainPageCollectionView A custom View with two level chained collection views and fancy transition animation. Demo Requirements iOS 9.0+ Xcode 8 Insta

A DSL to make animation easy on iOS with Swift.
A DSL to make animation easy on iOS with Swift.

This project is highly inspired by JHChainableAnimations, If you project is developed with Objective-C, use JHChainableAnimations instead. With DKChai

Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers
Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers

Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers. It's magic. Features Animate a

Elegant SVG animation kit for swift
Elegant SVG animation kit for swift

Elephant This is SVG animation presentation kit for iOS. Example You can run example app. Please open Example-iOS/Elephant-iOS.xcworkspace! Usage You

Comments
  • fillMode uses fixed value

    fillMode uses fixed value

    Hi. Thank you for good library.

    Is there any reason why fillMode is fixed value?

    https://github.com/cats-oss/Sica/blob/3adaee7047f5a896cb3c57da136e7b73a9383672/Sica/Source/Animator.swift#L110

    and why isRemovedOnCompletion's default value is false? even though CAAnimation's default value is true.

    https://github.com/cats-oss/Sica/blob/3adaee7047f5a896cb3c57da136e7b73a9383672/Sica/Source/Animator.swift#L103

    日本語の説明は以下を参考してください。 https://qiita.com/hachinobu/items/57d4c305c907805b4a53#comment-0709844b92e4f16057aa

    opened by hmhv 2
  • Modifications of view.sica

    Modifications of view.sica

    There are 4 modifications in this PR.

    • 544bb451de4d6501189c2be339df7ff9e15e3a9e add deinit test

    • 971f3308cdb0617ecb522bbdbfbc8742cd2f3fa2 fix reference cycle

    layer.sica caused reference cycle because sica instance has strong reference of layer instance.

    • aecba50a6ffc2b8c20a8407758611976c11d328e fix target membership

    CALayer+Sica.swift and View+Sica.swift were not contained tvOS and macOS target membership. Therefore, view.sica and layer.sica were not accessible in tvOS and macOS.

    • 8c29d55fd73db4a6c5687271dacff25da232706e update README
    opened by marty-suzuki 2
  • Add flag whether or not to include the delay in the duration calculation when parallel

    Add flag whether or not to include the delay in the duration calculation when parallel

    When .run(type: .parallel) is executed after setting delay greater than 0 for add**Animation, the animation terminates in the middle. I guessed that this is because the beginTime (=delay) is not included in the calculation of totalDuration when running in parallel.

    However, this fix may have unexpected effects on other developers, so I added a static flag to change the behavior as an option.

    opened by naoto0n2 1
Releases(0.4.1)
Owner
CATS Open Source Softwares
OSS from CATS ( CyberAgent Advanced Technology Studio ).
CATS Open Source Softwares
MapTeam - A type-safe, Swift-language layer over SQLite3

SQLite.swift A type-safe, Swift-language layer over SQLite3. SQLite.swift provid

Théotime 0 Jan 18, 2022
Stagehand provides a modern, type-safe API for building animations on iOS

Stagehand Stagehand provides a modern, type-safe API for building animations on iOS. Stagehand is designed around a set of core ideas: Composition of

Cash App 118 Dec 3, 2022
Design and prototype customized UI, interaction, navigation, transition and animation for App Store ready Apps in Interface Builder with IBAnimatable.

Design and prototype customized UI, interaction, navigation, transition and animation for App Store ready Apps in Interface Builder with IBAnimatable.

IBAnimatable 8.6k Jan 2, 2023
Run animations at high frame rates on iPhone 13 Pro

Run animations at high frame rates on iPhone 13 Pro Background When using a UIViewPropertyAnimator to animate objects on iPhone 13 Pro, CoreAnimation

Duraid Abdul 5 Aug 8, 2022
An experiment for using SwiftUI's custom timing Animation to create an orbital-like animation.

Orbital-SwiftUI-Animation An experiment for using SwiftUI's custom timing curve to create an orbital-like animation. How it looks: How it works: Apply

Mostafa Abdellateef 7 Jan 2, 2023
SwiftUI-Text-Animation-Library - Text animation library for SwiftUI

⚠️ This repository is under construction. SwiftUI Text Animation Library Make yo

null 28 Jan 8, 2023
Swiftui-animation-observer - Track SwiftUI animation progress and completion via callbacks

SwiftUI Animation Observer Track SwiftUI animation progress and completion via c

Gordan Glavaš 9 Nov 5, 2022
library performs interaction with UI interface

StartGravity: Agilie Team would like to offer you our new lightweight open-source library called AGInterfaceInteraction. Our library with the new inte

Agilie Team 157 Nov 29, 2022
Fluid - Use a declarative syntax to build your user interface using UIKit like SwiftUI

Fluid Fluid is powered by ResultBuilder and a custom layout engine. You can uses

HZ.Liu 13 Dec 9, 2022