ValueAnimator 0.6.9

ValueAnimator 0.6.9

brownsoo 维护。



  • 作者:
  • brownsoo

ValueAnimator

CI Status Version License Platform codebeat badge

  • 在 'onChanged' 函数中处理多个属性

示例

Demo for UIView animation

用法

ValueAnimator 使用缓动函数将初始值转换为目标值。

简单动画

let animator = ValueAnimator.animate("some", from: 0, to: 360, duration: 1.0,
    onChanged: { p, v in 
        print("property \(p): \(v.value)")
    },
    easing: EaseCircular.easeIn())
animator.resume()

使用两个值的 YoYo 动画

let yoyoAni = ValueAnimator.animate(
    props: ["h", "w"], 
    from: [20, 30], 
    to: [5, 150], 
    duration: 1.4, 
    easing: EaseSine.easeInOut(), 
    onChanged: { p, v in
        if p == "h" {
            let width = self.rect1.bounds.width
            self.rect1.frame = CGRect(x: 24, y: 140, width: width, height:v.cg)
        } else {
            let height = self.rect1.bounds.height
            self.rect1.frame = CGRect(x: 24, y: 140, width:v.cg, height: height)
        }
    }, 
    option: ValueAnimator.OptionBuilder()
        .setYoyo(true)
        .build())
yoyoAni.resume()

线程

ValueAnimator 使用自己的工作线程。但回调 changeCallbackendCallback 在主线程中调用。如果你想在工作线程中调用,只需将 'callbackOnMainThread' 属性设置为 false。

let someView: UIView!
let animator = ValueAnimator.animate("some", from: 0, to: 1, duration: 1.0,
    onChanged: { p, v in 
        // called in ValueAnimator's work-thread
    },
    easing: EaseCircular.easeIn())
animator.callbackOnMainThread = false
animator.resume()

示例

要运行示例项目,请克隆存储库,并运行 open ValueAnimator.xcworkspace。您可以查看 ValueAnimatorExample 项目。

安装

CocoaPods

只需将以下行添加到您的 Podfile 中

pod 'ValueAnimator'

Swift Package Manager

  • 打开 Xcode
  • 转到 文件 > Swift 包 > 添加包依赖...
  • 将此 GitHub 仓库 URL (https://github.com/brownsoo/ValueAnimator)粘贴到搜索栏中。
  • 从搜索结果中选择 ValueAnimator 仓库。

作者

brownsoo, @medium

许可证

ValueAnimator 可在 MIT 许可下使用。有关更多信息,请参阅 LICENSE 文件。