Animo 1.4.0

Animo 1.4.0

测试已测试
Lang语言 SwiftSwift
许可证 MIT
Released上次发布2018年6月
SPM支持 SPM

John Estropia 维护。



Animo 1.4.0

  • 作者:
  • John Rommel Estropia

Animo

Version Platform License Carthage compatible

使用类似 SpriteKit 的动画构建器 bring life to CALayers。

preview

为何使用 Animo?

因为声明 CAAnimation(尤其是使用 CAAnimationGroup)非常冗长和繁琐。

Animo 将其转换成这样

let positionAnimation = CABasicAnimation(keyPath: "position")
positionAnimation.fromValue = NSValue(CGPoint: fromPoint)
positionAnimation.toValue = NSValue(CGPoint: toPoint)

let colorAnimation = CABasicAnimation(keyPath: "backgroundColor")
colorAnimation.fromValue = fromColor.CGColor
colorAnimation.toValue = toColor.CGColor

let animationGroup = CAAnimationGroup()
animationGroup.animations = [positionAnimation, colorAnimation]
animationGroup.fillMode = kCAFillModeForwards
animationGroup.removedOnCompletion = false
animationGroup.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)

someView.layer.addAnimation(animationGroup, forKey: "animationGroup")

到这样

someView.layer.runAnimation(
    Animo.group(
        Animo.move(from: fromPoint, to: toPoint, duration: 1),
        Animo.keyPath("backgroundColor", from: fromColor, to: toColor, duration: 1),
        timingMode: .EaseInOut,
        options: Options(fillMode: .Forwards)
    )
)

特性列表

  • 实现了来自 http://easings.net/ 的所有时间模式。
  • 选择如何使用分组工具混合动画
    • group(...)
    • sequence(...)
    • autoreverse(...)
    • wait(...)
    • replay(...)replayForever(...)
  • 不需要使用 NSValue 对本地类型和结构类型进行装箱!Animo 会为您完成
    • Int8
    • Int16
    • Int32
    • Int64
    • UInt8
    • UInt16
    • UInt32
    • UInt64
    • Int
    • UInt
    • CGFloat
    • Double
    • Float
    • CGPoint
    • CGSize
    • CGRect
    • CGAffineTransform
    • CGVector
    • CATransform3D
    • UIEdgeInsets
    • UIOffset
    • NSRange
  • 无需在 CGColorUIColor 之间纠结!Animo 会自动为您转换以下类型,您只需始终使用 UIKit 对象即可
    • UIColorCGColor
    • UIImageUIImage
    • UIBezierPathCGPath
  • 不再需要将 M_PI 强制转换为类型,现在只需使用为 CGFloatDoubleFloat 定制的角度到弧度(反之亦然)扩展即可!

这是一个稍微复杂些的动画,展示了 Animo 其他可以做到的事情

someView.layer.runAnimation(
    Animo.sequence( // Runs a list of animations in sequence
        Animo.wait(1), // Waits for a certain interval before running the next animation
        Animo.replayForever( // Replays the animation endlessly
            Animo.sequence(
                Animo.move( // Moves the layer's position
                    by: CGPoint(x: 100, y: 200), // "by", "from", and "to" arguments are supported
                    duration: 2,
                    timingMode: .Spring(damping: 1) // simplistic spring function that doesn't rely on physics
                ),
                Animo.rotateDegrees( // Rotates the layer (degrees and radians variants are supported)
                    by: -180,
                    duration: 1,
                    timingMode: .EaseInOutBack
                ),
                Animo.autoreverse( // Auto-reverses the animation
                    Animo.keyPath(
                        "cornerRadius", // Any custom KVC key is supported as well!
                        to: 10,
                        duration: 1,
                        timingMode: .EaseInOutBack
                    )
                ),
                Animo.group( // Runs multiple animations together
                    Animo.scaleX(
                        by: 2,
                        duration: 1,
                        timingMode: .EaseInOutBack
                    ),
                    Animo.scaleY(
                        by: 0.5,
                        duration: 1,
                        timingMode: .EaseInOutBack
                    )
                ),
                Animo.wait(1),
                Animo.move(
                    by: CGPoint(x: -100, y: -200),
                    duration: 2,
                    timingMode: .EaseInOutBack
                ),
                Animo.rotateDegrees(
                    by: 180,
                    duration: 1,
                    timingMode: .EaseInOutBack
                ),
                Animo.group(
                    Animo.scaleX(
                        to: 1,
                        duration: 1,
                        timingMode: .EaseInOutBack
                    ),
                    Animo.scaleY(
                        to: 1,
                        duration: 1,
                        timingMode: .EaseInOutBack
                    )
                )
            )
        )
    )
)

使用 CocoaPods 安装

添加

pod 'Animo'

到您的 Podfile 并运行 pod install

使用 Carthage 安装

添加

github "eure/Animo" >= 1.2.0

到您的 Cartfile 并运行 carthage update

作为 Git 子模块安装

运行

git submodule add https://github.com/eure/Animo.git <destination directory>

将 Animo 安装为框架

Animo.xcodeproj 拖放到您的项目中

直接将 Animo 包含到您的应用模块中

将所有 .swift 文件添加到您的项目中。

许可协议

Animo 采用 MIT 许可发布。请参阅 LICENSE 文件获取更多信息。