Type-safe CAAnimation wrapper. It makes preventing to set wrong type values.

Overview

TheAnimation

Platform Language Carthage Version License CI Status

TheAnimation is Type-safe CAAnimation wrapper.

Introduction

For example, if you want to animate backgroundColor with CABasicAnimation, you need to consider type because fromValue property and so on are Any?.

If you use BasicAnimation of TheAnimation, you can animate backgroundColor without considering type! (AnimationKeyPaths.backgroundColor is AnimationKeyPath<CGColor> type.)

Usage

The way of making an animation is almost similar CAAnimation. But you need to use animation.animate(in:) method instead of using layer.add(_:forKey:).

let view = UIView()

let animation = BasicAnimation(keyPath: .opacity)
animation.fromValue = 0
animation.toValue   = 1
animation.duration  = 1
animation.animate(in: view)

animation.animate(in:) returns AnimaitonCanceller. You can cancel an animation with it.

let canceller = animation.animate(in: view)
canceller.cancelAnimation()

Example

To run the example project, clone the repo, and open Example directory.

Correspondence Table

CAAnimation TheAnimation
CAPropertyAnimation PropertyAnimation
CABasicAnimation BasicAnimation
CAKeyframeAnimation KeyframeAnimation
CASpringAnimation SpringAnimation
CATransition TransitionAnimation
CAAnimationGroup AnimationGroup

Add new AnimationKeyPath

You can add AnimationKeyPath like this.

extension AnimationKeyPaths {
    static let newKeyPath = AnimationKeyPath<CGFloat>(keyPath: "abcd")
}

Handle animation did Start / Stop

You can handle animation did Start with func setAnimationDidStart(handler:). In addition, you can handle animation did Stop with func setAnimationDidStop(handler:).

let view = UIView()

let animation = BasicAnimation(keyPath: .opacity)
animation.fromValue = 0
animation.toValue   = 1
animation.duration  = 1

animation.setAnimationDidStart {
    // do something
}

animation.setAnimationDidStop { finished in
    // do something
}

animation.animate(in: view)

Requirements

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

Installation

Carthage

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

github "marty-suzuki/TheAnimation"

CocoaPods

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

pod 'TheAnimation'

Author

marty-suzuki, [email protected]

License

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

You might also like...
Swift extension which adds start, animating and completion closures for CAAnimation objects. Aka, CAAnimation + Closure / Block
Swift extension which adds start, animating and completion closures for CAAnimation objects. Aka, CAAnimation + Closure / Block

Swift-CAAnimation-Closure Swift extension which adds start, animating and completion closures for CAAnimation objects. Aka, CAAnimation + Closure or C

Type-safe observable values and collections in Swift

GlueKit ⚠️ WARNING ⚠️ This project is in a prerelease state. There is active work going on that will result in API changes that can/will break code wh

🎯 PredicateKit allows Swift developers to write expressive and type-safe predicates for CoreData using key-paths, comparisons and logical operators, literal values, and functions.
🎯 PredicateKit allows Swift developers to write expressive and type-safe predicates for CoreData using key-paths, comparisons and logical operators, literal values, and functions.

🎯 PredicateKit PredicateKit is an alternative to NSPredicate allowing you to write expressive and type-safe predicates for CoreData using key-paths,

Type-safe networking abstraction layer that associates request type with response type.

APIKit APIKit is a type-safe networking abstraction layer that associates request type with response type. // SearchRepositoriesRequest conforms to Re

A custom UIControl which functions like UISlider where you can set multiple intervals with different step values for each interval.
A custom UIControl which functions like UISlider where you can set multiple intervals with different step values for each interval.

MultiStepSlider A custom UIControl which functions like UISlider where you can set multiple intervals with different step values for each interval. Th

Time is a Swift package that makes dealing with calendar values a natural and straight-forward process.

Time Time is a Swift package that makes dealing with calendar values a natural and straight-forward process. Working with calendars can be extremely c

MemoryCache - type-safe, thread-safe memory cache class in Swift

MemoryCache is a memory cache class in swift. The MemoryCache class incorporates LRU policies, which ensure that a cache doesn’t

Modern thread-safe and type-safe key-value observing for Swift and Objective-C

Now Archived and Forked PMKVObserver will not be maintained in this repository going forward. Please use, create issues on, and make PRs to the fork o

A Protocol-Oriented NotificationCenter which is type safe, thread safe and with memory safety
A Protocol-Oriented NotificationCenter which is type safe, thread safe and with memory safety

A Protocol-Oriented NotificationCenter which is type safe, thread safe and with memory safety. Type Safe No more userInfo dictionary and Downcasting,

NoticeObserveKit is type-safe NotificationCenter wrapper.

NoticeObserveKit NoticeObserveKit is type-safe NotificationCenter wrapper. // .keyboardWillShow is a static property. Notice.Center.default.observe(na

NoticeObserveKit is type-safe NotificationCenter wrapper.

NoticeObserveKit NoticeObserveKit is type-safe NotificationCenter wrapper. // .keyboardWillShow is a static property. Notice.Center.default.observe(na

A type-safe swifty wrapper around NSCache.

swift-cache A type-safe swifty wrapper around NSCache. Getting Started Add swift-cache as a dependency to your project using SPM. .package(url: "https

A type-safe auto-generated Swift wrapper around fluentui-emoji
A type-safe auto-generated Swift wrapper around fluentui-emoji

fluentui-emoji.swift A type-safe auto-generated Swift wrapper around fluentui-emoji. Usage Requirements iOS 13+ macOS 10.15+ tvOS 13+ watchOS 6+ Insta

Type-Erased Existential Generic AsyncSequence Values in Swift

AnyAsyncSequence AnyAsyncSequence allows you to expose AsyncSequence interfaces in your APIs without exposing the underlying sequence type, while cont

MQTagged provides a Tagged structure which helps differentiating between values of the same type.

MQTagged provides a Tagged structure which helps differentiating between values of the same type.

A Codable Undefinable type for handling JSON undefined values.

Undefinable Overview The purpose of this type is represent the JSON undefined state in Swift structs and classes. The Undefinable enum is a generic wi

A beautiful set of predefined colors and a set of color methods to make your iOS/OSX development life easier.
A beautiful set of predefined colors and a set of color methods to make your iOS/OSX development life easier.

Installation Drag the included Colours.h and Colours.m files into your project. They are located in the top-level directory. You can see a demo of how

A phantom type is a custom type that has one or more unused type parameters.

PhantomTypes A phantom type is a custom type that has one or more unused type parameters. Phantom types allow you to enforce type-safety without sacri

UICKeyChainStore is a simple wrapper for Keychain on iOS, watchOS, tvOS and macOS. Makes using Keychain APIs as easy as NSUserDefaults.

UICKeyChainStore UICKeyChainStore is a simple wrapper for Keychain that works on iOS and OS X. Makes using Keychain APIs as easy as NSUserDefaults. Lo

Releases(0.4.0)
Owner
Taiki Suzuki
AbemaTV / University of Aizu 18th
Taiki Suzuki
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
🚀 It Makes easy to track your task 🔥 Beautiful & Animated UI👨🏻‍💻 . Contributions are always welcome 🤗

Taskey ?? What is Taskey ?? ? Taskey is an application build in SwiftUI to track your task with a beautiful animations and UI . Also used core data to

Mohd Yasir 36 Nov 20, 2022
DaisyChain is a micro framework which makes UIView animations chaining dead simple.

DaisyChain DaisyChain is a micro framework which makes UIView animations chaining dead simple. It uses the exact same interface you are familiars with

Ali Karagoz 31 Nov 3, 2022
🚀 It Makes easy to track your task 🔥 Beautiful & Animated UI👨🏻‍💻 . Contributions are always welcome 🤗

Taskey ?? What is Taskey ?? ? Taskey is an application build in SwiftUI to track your task with a beautiful animations and UI . Also used core data to

AppLobby 36 Nov 20, 2022
Wave is a spring-based animation engine for iOS that makes it easy to create fluid, interruptible animations that feel great.

Wave is a spring-based animation engine for iOS and iPadOS. It makes it easy to create fluid, interactive, and interruptible animations that feel great.

Janum Trivedi 1.2k Jan 8, 2023
Swift wrapper for Discord's API. Maintained fork of Azoy's Sword.

Sword - A Discord Library for Swift Requirements macOS, Linux, iOS, watchOS, tvOS (no voice for iOS, watchOS, or tvOS) At least Swift 5.3 Adding Sword

Sketch 38 Jan 3, 2023
LottieView - Wrapper around Lottie in SwiftUI that allows chaining animations & triggering callbacks at certain frames

LottieView is a Wrapper around Lottie in SwiftUI that allows chaining animations & triggering callbacks at certain frames

Ahmed Ramy 0 Jan 23, 2022
Emil 3 Jan 31, 2022
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

Kyle Hickinson 64 Sep 2, 2022