I’m working on a gestures-driven media player app for iOS and I’m trying to implement the usual mp3reader behavior that if you press the “back” button once will replay the current playing item from the beginning but if you press the “back” button twice consecutively will skip to the previous song.
I added a UISwipeGestureRecognizer to my UIView and managed to get the “replay” function working with the single swipe.. But I don’t know how to detect two consecutive swipes! Can you guys help me?
You could think of implementing that functionality by means of a single finger swipe vs. double finger swipe. In that case,
UISwipeGestureRecognizerwill offer anumberOfTouchesRequiredproperty to manage this.Otherwise, you will need to do the following:
add a swipe counter to your controller;
when the first swipe is detected, you increment the counter and starts an
NSTimer;when the timer fires, if the swipe counter is 1, you know a single swipe was detected;
3b. when the timer fires, you disable the timer;
when a new swipe is detected, if the swipe counter is 1 (and you should increment it to 2), then you handle the double swipe action; you then reset the counter.
I really do think that the single-finger/double-finger swipe is the way to go.