Created
February 3, 2016 23:47
-
-
Save almostintuitive/8210fb19d3b939a2192f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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