如何将 RxSwift 与 NVActivityIndi​​catorView 一起使用?

How to use RxSwift with NVActivityIndicatorView?

我正在尝试将 NVActivityIndicatorViewRxSwiftMVVM 一起使用。 我正在扩展 NVActivityIndicatorView,如下所示:

extension Reactive where Base: NVActivityIndicatorView {

/// Bindable sink for `startAnimating()`, `stopAnimating()` methods.
public var isAnimating: Binder<Bool> {
    return Binder(self.base) { activityIndicator, active in
        if active {
            activityIndicator.startAnimating()
        } else {
            activityIndicator.stopAnimating()
        }
    }
}}

并像这样绑定数据:

splashVM.loading.bind(to: NVActivityIndicatorView.rx.isAnimating).disposed(by: disposeBag)

但是我得到了这个错误:

Instance member 'isAnimating' cannot be used on type 'Reactive<NVActivityIndicatorView>'

如果我将 isAnimation 设置为静态,该错误就会消失,但会弹出另一个错误:

Instance member 'base' cannot be used on type 'Reactive<Base>'

到底是什么问题?我应该改变什么?

你绑定错了。您需要绑定到特定的 activity 指标视图而不是 class:

let activityIndicatorView: NVActivityIndicatorView

splashVM.loading
    .bind(to: activityIndicatorView.rx.isAnimating)
    .disposed(by: disposeBag)