Way to make a UIButton continuously fire during a press-and-hold situation?

后端 未结 4 1237
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 19:21

You know how Mario just keeps running to the right when you press and hold the right-button on the D-Pad? In the same manner, I want my UIButton to continuously fire its act

4条回答
  •  -上瘾入骨i
    2020-11-29 20:00

    And Now for Something Completely Different:
    ReactiveCocoa 6.

    self.button.reactive
        .controlEvents([.touchDown])
        .observeValues { button in
            SignalProducer.timer(interval: .milliseconds(500), on: QueueScheduler.main)
                .take(until: button.reactive.controlEvents([.touchDragOutside, .touchDragExit, .touchUpInside, .touchUpOutside, .touchCancel]).map { _ in return })
                .prefix(value: Date())
                .startWithValues { date in
                    NSLog("\(date)")
                }
            }
    

提交回复
热议问题