ios - ReactiveCocoa 5 动画

标签 ios swift animation reactive-cocoa reactive-cocoa-5

在通过 ReactiveSwift Signal Producer 向 View 的 alpha 属性发送一些值后,我尝试对 View 的 alpha 属性进行动画

以下是我目前在没有动画的情况下的做法。

// Somewhere in View Model (for all code below)
let shouldShowShutter = MutableProperty<Bool>(false)

// In my View
self.shutterButton.reactive.alpha <~ self.viewModel.shouldShowShutter.map({ (show) -> CGFloat in
        return show ? 1:0.0
    })

我可以通过以下方式不优雅地为 View 设置动画:

self.viewModel.shouldShowShutter.producer.startWithSignal { (observer, disposable) in
            observer.map({ (show) -> CGFloat in
                return show ? 1:0.0
            }).observeValues({ [unowned self] (alpha) in
                UIView.animate(withDuration: 0.5, animations: { 
                    self.shutterButton.alpha = alpha
                })
            })
        }

但我应该能够使用 ReactiveAnimation 为 View 添加动画:

self.shutterButton.reactive.alpha <~ self.viewModel.shouldShowShutter.map({ (show) -> CGFloat in
        return show ? 1:0.0
    }).animateEach(duration: 0.2).join(.Concat)

问题:在我提出问题时,ReactiveCocoaLayoutReactiveAnimation 似乎都不再工作了,至少在 Swift 3 或 ReactiveCocoa 5,因为它们很大程度上依赖于遗留的 RACSignals

是否有更优雅的方式使用 ReactiveCocoa 5 将信号流动画化到 ReactiveCocoa 组件?

最佳答案

我以前不知道 ReactiveAnimation,但我真的很喜欢这种方法。

所以我将其更新为 RAC 5.0/Swift 3.2,看看 my fork 。我还将创建一个拉取请求,让我们看看是否能让项目恢复生机。

我包含了一个小型 iOS 演示项目来演示其用法:

label.reactive.center <~ SignalProducer.timer(interval: .seconds(1), on: QueueScheduler.main)
  .map { _ in return self.randomPoint() }
  // In order to demonstrate different flatten strategies,
  // the animation duration is larger than the animation interval,
  // thus a new animation begins before the running animation is finished
  .animateEach(duration: 1.5, curve: .EaseInOut)
  // With the .concat flatten strategy, each animations are concatenated.
  // Each animation finisheds, before the next one starts.
  // This also means, that animations are queued
  .flatten(.concat)
  // With the .merge flatten strategy, each animation is performed immediately
  // If an animation is currently running, it is cancelled and the next animation starts from the current animation state
  //.flatten(.merge)

关于ios - ReactiveCocoa 5 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44525369/

相关文章:

java - PaintComponent() 可以在 AbstractAction 类中使用吗?

ios - Swift:按元素对字典进行约束扩展

ios - 在十进制键盘上添加 +/- 按钮

ios - 如何使用自定义标题将单元格分成几个部分?

ios - Swift 代码签名错误

ios - `UITabBarController` 切换标签时去除黑色背景

android - 如何动画缩放相对布局(其中包含许多布局和 ImageViews 里面)

ios - 自定义 iOS 的应用程序 :didFinishLaunchingWithOptions: method in a Cordova/Ionic project

ios - iOS聊天应用程序如何在后台保持运行?

jquery - CSS3 - 添加类来触发动画并在完成时删除类