ThenAnimatable 0.0.1

ThenAnimatable 0.0.1

ghost 维护。



  • ghost

#ThenAnimatable

使用 ThenAnimatable 在 Interface Builder 中设计和原型化定制的 UI、交互、导航、过渡和动画,为 App Store 准备的应用程序。从 IBAnimatable 分支

如何安装

手动安装

ThenAnimatable 文件夹复制并粘贴到您的 Xcode 项目中。

Swift 包管理器

要使用 Apple 的 Swift 包管理器进行集成,请在您的 Package.swift 文件中将以下内容作为依赖项添加

.package(url: "https://github.com/ghostcrying/ThenAnimatable.git", .upToNextMajor(from: "0.0.1"))

CocoaPods

在您的 Podfile 中添加以下条目

   pod 'ThenAnimatable'

Carthage

在您的 Cartfile 中添加以下条目

   github "ghostcrying/ThenAnimatable"

Accio

在您的 Package.swift 中添加以下条目

.package(url: "https://github.com/ghostcrying/ThenAnimatable.git", .upToNextMajor(from: "0.0.1")),

接下来,将 ThenAnimatable 添加到您的 App targets 依赖项中,如下所示

.target(
    name: "App",
    dependencies: [
        "ThenAnimatable",
    ]
),

如何通过编程进行动画化

如上所示,我们可以在 Interface Builder 中完全在不写任何代码的情况下原型化一个 App,但 ThenAnimatable 同样提供了让我们完全控制 UI 和动画的 API。ThenAnimatable 提供了类似 Promise 的简单 API。我们可以轻松地在单行中调用它们。

view.animate(.pop(repeatCount: 1)) // pop animation for the view
view.animate(.squeezeFade(way: .in, direction: .left)) // squeeze and fade in from left animation

您可以在 Swift playground 页面 - 预定义动画 中对这些预定义的动画进行尝试。

动画属性

有一些属性我们可以修改来自定义动画。我们需要做的是传递参数到 animate() 方法来开始动画。

view.animate(.squeeze(way: .in, direction: .left), duration: 1, damping: 1, velocity: 2, force: 1)

你可以在 Swift playground 页面 - Animation Properties 中尝试所有动画的不同参数。

链式动画

有时候,我们需要在之前的动画之后运行更多动画。使用 ThenAnimatable,我们可以轻松地使用类似于 promise 的 API 将所有动画连在一起,提供流畅的用户体验。

// We can chain the animations together, it is the source code of animated GIF in "Animate in Swift playground" section
view.animate(.squeezeFade(way: .in, direction: .down))
    .then(.pop(repeatCount: 1))
    .then(.shake(repeatCount: 1))
    .then(.squeeze(way: .in, direction: .down))
    .then(.wobble(repeatCount: 1))
    .then(.flip(along: .x))
    .then(.flip(along: .y))
    .then(.slideFade(way: .out, direction: .down))

动画延迟

我们可以使用 delay 方法延迟下一个动画。

view.animate(.squeeze(way: .in, direction: .left))
    .delay(0.5)
    .then(.shake(repeatCount: 3))

我们也可以延迟第一个动画。

view.delay(2)
    .then(.squeeze(way: .in, direction: .left))

完成处理程序

我们可以向动画完成时执行的代码块添加一个完成处理程序/闭包。

view.animate(.squeeze(way: .in, direction: .left))
    .completion { print("Animations finished!") }

许可证

ThenAnimatable采用MIT许可发布。有关详细信息,请参阅LICENSE