gpt4 book ai didi

ios - ReactiveCocoa 5 动画

转载 作者:可可西里 更新时间:2023-11-01 01:19:33 26 4
gpt4 key购买 nike

在我通过 ReactiveSwift Signal Producer 向 View 的 alpha 属性发送一些值后,我正在尝试为 View 的 设置动画 属性。

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

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

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com