Union 0.5.0

Union 0.5.0

测试已测试
语言语言 SwiftSwift
许可 MIT
发布日期上次发布2015年10月
SPM支持SPM

hirohisa维护。



Union 0.5.0

  • Hirohisa Kawasaki

Union

使用Swift编写的iOS上下文转换动画管理器。为每层的动画创建动画任务,并在Union.Delegate上执行任务。

功能

  • [x] 支持 CABasicAnimation。
  • [x] 支持 CAKeyframeAnimation。
  • [ ] 支持 UIView.animateWithDuration 块。
  • [x] 链接到其他任务,使用属性 dependencies
  • [x] 支持 UIViewControllerTransitioningDelegate。
  • [ ] 支持 UITabBarControllerDelegate。

要求

  • iOS 8.0+
  • Xcode 7.0+ Swift 2.0

安装

手动安装

如果您不想使用上述依赖管理器之一,可以将Union手动集成到项目中。

内嵌框架

  • 打开终端,使用 cd 命令进入顶级项目目录,然后运行以下命令“if”您的项目不是作为git仓库初始化的

  • 通过运行以下命令将ImageLoader作为git 子模块添加

$ git submodule add https://github.com/TransitionKit/Union.git

示例

我用Union创建了一个示例动画,它来自dribbble.com上的“User-Profile-Interface-Animation”。

查看项目

用法

  1. 创建动画。
  2. 在Union.Delegate中实现动画任务。
  3. 在UINavigationControllerDelegate上调用手动转换。

创建动画

动画的单位是Union.Task。有两种创建它的方法

  • 使用层和动画进行初始化

    大多数情况是这种模式

let animation = Animation(layer:layer, animation:animation)
  • 使用延迟时间和完成块进行初始化

    在不涉及动画的过程中使用

let animation = Animation(delay: 0.3) {
    self.view.insertSubview(self.imageView, aboveSubview: self.backgroundView)
}

Union.Animation类

public class Animation {
    // public property
    public var delay: NSTimeInterval = 0.0 // animation start after delay time
    public var completion: () -> () = {} // block called when animation is finished

    public init(layer: CALayer, animation: CAPropertyAnimation) {
        self.layer = layer
        self.animation = animation
    }

    public init (delay: NSTimeInterval, completion: () -> ()) {
        self.delay = delay
        self.completion = completion
    }
}

在Union.Delegate中实现动画任务

通过UINavigationController使用Union.Delegate协议调用动画任务。

Union.Delegate协议

public protocol Delegate {
    func animationsBeforeTransitionTo(viewController: UIViewController) -> [Animation]
    func animationsDuringTransitionFrom(viewController: UIViewController) -> [Animation]
}
  • animationsBeforeTransitionTo(viewController: UIViewController) -> [Animation]

    在完成这些任务并调用由 UIViewController 显示的此方法后开始过渡。

  • animationsDuringTransitionFrom(viewController: UIViewController) -> [Animation]

    两个 UIViewController 调用的任务在过渡期间开始。所有任务完成后调用:context.completeTransition(true)

在 UINavigationControllerDelegate 上开始动画

extension ViewController: UINavigationControllerDelegate {
    func navigationController(navigationController: UINavigationController,
         animationControllerForOperation operation: UINavigationControllerOperation,
                         fromViewController fromVC: UIViewController,
                             toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return Union.Navigator.animate()
    }
}

在 UIViewControllerTransitioningDelegate 上开始动画

extension ViewController: UIViewControllerTransitioningDelegate {

    func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {

        return Union.Presentor.animate()
    }
}

许可

该项目可在 MIT 许可下使用。