RxSwift: Observable while a button holds down

后端 未结 2 1434
眼角桃花
眼角桃花 2021-02-11 02:36

How to create Observable which streams an event repeatedly while a button holds down?

2条回答
  •  一生所求
    2021-02-11 03:04

    To continue on rootcoder response, I had a situation where I had to recognize one longpress greater than three seconds

     let signinLongpress = signinButton.rx.controlEvent([.touchDown])
        signinLongpress
            .flatMapLatest { _ in
                Observable.interval(3, scheduler: MainScheduler.instance)
                    .take(1)
            }
            .subscribe(onNext:{ _ in print("do fun stuff only once when longpress detected")})
            .disposed(by: disposeBag)
    

提交回复
热议问题