2017-06-13 61 views
2

我試圖動畫一個視圖的alpha屬性後,我已經通過ReactiveSwift Signal Producer發送它的一些值。ReactiveCocoa 5動畫

以下是我目前如何做它無動畫。

// 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既不要」在我問這個問題的時候t似乎已經工作了,至少不是在Swift 3或者​​3210中,因爲他們依賴很多在傳統RACSignals

有沒有一種更優雅的方式來將信號流動畫成ReactiveCocoa組件與ReactiveCocoa 5?

回答

2

我以前不知道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) 
+0

你碰巧最終或添加演示?我很樂意瀏覽一下,看看我們可以做些什麼來重新啓動它。 –

+0

Ooops,我確實將它添加爲子模塊。現在修復它,直接在回購:https://github.com/iv-mexx/ReactiveAnimation – MeXx