Skip to content

Repository files navigation

ValueAnimator

VersionLicensePlatformactions workflow

Lightweight value interpolation with easing functions for Apple platforms.

ValueAnimator transitions a value from from to to over time and reports each frame through a callback. You can animate a single property or multiple properties simultaneously.

Demo

Demo for UIView animation

Usage

Simple animation

letanimator=ValueAnimator.animate("rotation",
from:0,
to:360,
duration:1.0,
easing:EaseCircular.easeIn(),
onChanged:{ property, value inprint("property \(property): \(value.value)")})
animator.resume()

Multiple properties + yoyo

letanimator=ValueAnimator.animate(
props:["h","w"],
from:[20,30],
to:[5,150],
duration:1.4,
easing:EaseSine.easeInOut(),
onChanged:{ property, value inif property =="h"{letwidth=self.rect1.bounds.width
self.rect1.frame =CGRect(x:24, y:140, width: width, height: value.cg)}else{letheight=self.rect1.bounds.height
self.rect1.frame =CGRect(x:24, y:140, width: value.cg, height: height)}},
option:ValueAnimator.OptionBuilder().setYoyo(true).setRepeatCount(2).build())
animator.resume()

Completion callback

letanimator=ValueAnimator.animate(
props:["alpha"],
from:[0.0],
to:[1.0],
duration:0.5,
onEnd:{print("animation completed")})
animator.resume()

Callback thread

By default, changeCallback and endCallback are dispatched on the main thread. If you need callbacks on the animation engine thread, set callbackOnMainThread = false.

letanimator=ValueAnimator.animate("opacity",
from:0,
to:1,
duration:1.0,
easing:EaseCircular.easeIn(),
onChanged:{ _, _ in
// called on ValueAnimator engine thread
},)
animator.callbackOnMainThread =false
animator.resume()

Static controls

ValueAnimator.finishAll()ValueAnimator.disposeAll()Task{letisAnimating=awaitValueAnimator.hasAnimation("opacity")print(isAnimating)}

Example

To run the example project, clone the repo, and run open ValueAnimator.xcworkspace. You can see ValueAnimatorExample project.

Requirements

  • iOS 13+
  • tvOS 13+
  • macOS 10.15+
  • watchOS 6+

Installation

  • Open Xcode
  • Go to File > Add Package Dependencies...
  • Paste this repository URL:
https://github.com/brownsoo/ValueAnimator
  • Select the ValueAnimator package and add it to your target.

Warning

CocoaPods support is now legacy and no longer actively updated. Please use Swift Package Manager for the latest updates.

Previously, you could add:

pod'ValueAnimator'

Author

brownsoo, @medium

License

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

About

Value transition swift utility

Topics

Resources

Stars

19 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages