Swiftpack.co - GodL/Animatable as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by GodL.
GodL/Animatable 1.0.6
A simpler way to set coreAnimation with PropertyWrapper.
⭐️ 10
🕓 2 years ago
iOS
.package(url: "https://github.com/GodL/Animatable.git", from: "1.0.6")

Animatable

✨ A simpler way to set coreAnimation with PropertyWrapper.

At a Glance

Initialize animations.

    enum Animations {
        struct TranslationAnimation: AnimatedType {
            var animation: CAAnimation {
                let animation = CABasicAnimation(keyPath: "transform.translation.x")
                animation.duration = 2
                animation.toValue = 200
                return animation
            }
        }

        struct ScaleAnimation: AnimatedType {
            var animation: CAAnimation {
                let animation = CABasicAnimation(keyPath: "transform.scale")
                animation.duration = 2
                animation.toValue = 2
                return animation
                }
            }
        }

Use animations with PropertyWrapper

    @Animatable(animated: Animations.TranslationAnimation(), configure: {
        if isRepeat {
            $0.autoreverses = true
            $0.repeatCount = 100
            }
    })
    var translationView: UILabel = UILabel()

    @Animatable(animated: Animations.ScaleAnimation(), configure: {
        if isRepeat {
            $0.autoreverses = true
            $0.repeatCount = 100
            }
    })
    var scaleView: UILabel = UILabel()

    @Animatable(animated: AnimationGroup(Animations.TranslationAnimation(), Animations.ScaleAnimation()), configure: {
        if isRepeat {
            $0.autoreverses = true
            $0.repeatCount = 100
            }
        })
    var combineView: UILabel = UILabel()
    
    $translationView.startAnimation()
    $scaleView.startAnimation()
    $combineView.startAnimation()

Tips

You can use projectedValue $ to startAnimation and stopAnimation

Installation

import PackageDescription

let package = Package(
name: "MyAwesomeApp",
dependencies: [
.Package(url: "https://github.com/GodL/Animatable.git", majorVersion: 1.0.6),
],
targets: [
.target(
name: "MyAwesomeApp",
dependencies: ["Animatable"])
]
)
  • Using [Cococpods]:
pod 'Animatable', '~> 1.0.6'

License

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

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics