如何使用 rxSwift 在 5 秒内禁用按钮点击?

问题描述 投票:0回答:0

rxSwift 版本:

pod 'RxSwift', '6.2.0'
pod 'RxCocoa', '6.2.0'

TrueBtn.rx.tap.throttle(.seconds(5), scheduler: MainScheduler.instance)
.subscribe(onNext: { [weak self] in

print("TrueBtn-true")

}).disposed(by: bag)

如何使用 rxSwift 在 5 秒内禁用按钮点击?

同一视图中有一个错误的按钮。

FalseBtn.rx.tap.throttle(.seconds(5), scheduler: MainScheduler.instance)
.subscribe(onNext: { [weak self] in

print("FalseBtn-false")

}).disposed(by: bag)

我点击 true 按钮,1 秒后再次点击 true 按钮。然后我点击错误按钮。 现在的结果是:

TrueBtn-true
等一秒
FalseBtn-假
等待 4 秒
TrueBtn-真

我想要这个:

TrueBtn-true
等一秒
FalseBtn-假
等待 4 秒

rx-swift
© www.soinside.com 2019 - 2024. All rights reserved.