在通过. _ 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)
问题:在我提出这个问题时ReactiveCocoaLayout
,ReactiveAnimation
两者似乎都不再起作用了,至少在 Swift 3 上没有,或者ReactiveCocoa 5
因为它们在很大程度上依赖于 legacy RACSignals
。
有没有更优雅的方法来使用 ReactiveCocoa 5 为 ReactiveCocoa 组件的信号流设置动画?