如何使用ReactiveX按顺序执行异步调用? 即,在第一个完成后执行第二个呼叫。如何使用ReactiveX按顺序执行异步
更具体地说,我在iOS中使用RxSwift,我想链接在一起的异步是UIView
动画(而不是调用第一个的completion
块内的第二个动画)。
我知道我有其他选项,例如Easy Animation,但我想利用Rx,因为我已经在使用它来处理流。
而且,一个解决办法是(3个链式动画):
_ = UIView.animate(duration: 0.2, animations: {
sender.transform = CGAffineTransformMakeScale(1.8, 1.8)
})
.flatMap({ _ in
return UIView.animate(duration: 0.2, animations: {
sender.transform = CGAffineTransformMakeScale(0.8, 0.8)
})
})
.flatMap({ _ in
return UIView.animate(duration: 0.2, animations: {
sender.transform = CGAffineTransformIdentity
})
})
.subscribeNext({ _ in })
但是我正在寻找的东西更优雅,其中RX这样做的正确方法。
怎么了你的代码示例?你的意思是它是伪代码吗?你在'Void'上调用'flatMap',而不是'SequenceType'或'Observable'。另外,animateWithDuration:动画:',而不是'animate:动画:'。我不确定你打算加入该代码的意图。 – solidcell
我创建了'animate:...'方法来返回一个observable,所以不,不是伪代码 –