2

通过. _ alpha_ReactiveSwift Signal Producer

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

// 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
    })

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

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

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因为它们在很大程度上依赖于 legacy RACSignals

有没有更优雅的方法来使用 ReactiveCocoa 5 为 ReactiveCocoa 组件的信号流设置动画?

4

1 回答 1

2

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

所以我为 RAC 5.0 / Swift 3.2 更新了它,看看我的 fork。我还将创建一个拉取请求,让我们看看是否可以让项目恢复活力。

我已经包含了一个小的 iOS Demo 项目来演示使用:

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)
于 2017-06-16T17:04:58.687 回答