Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almostintuitive/8210fb19d3b939a2192f to your computer and use it in GitHub Desktop.
Save almostintuitive/8210fb19d3b939a2192f to your computer and use it in GitHub Desktop.
let pan = UIPanGestureRecognizer()
let pinch = UIPinchGestureRecognizer()
let panStarted = pan.rx_event.filter { $0.state == .Began }
let panEnded = pan.rx_event.filter { $0.state == .Ended }
let pinchStarted = pinch.rx_event.filter { $0.state == .Began }
let pinchEnded = pinch.rx_event.filter { $0.state == .Ended }
// condition: when both pan and pinch ended
let bothGesturesEnded = Observable.of(panEnded, pinchEnded).merge()
// when both pan and pinch has begun, do this:
let _ = Observable.of(panStarted, pinchStarted).merge(maxConcurrent: 1).subscribeNext { _ in
print("started")
// create a timer that ticks every second, until 3 or until pan and pinch ended
let timer = Observable<Int>.timer(repeatEvery: 1).take(3).takeUntil(bothGesturesEnded)
timer.subscribe(onNext: { count in
// when a tick happens, do this:
print("tick: \(count)")
}, onCompleted: {
// when the timer completes, do this:
print("completed")
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment