I am coding the previous/next buttons of a music player. I need these UIButtons to have dual purpose.
1. Tap – Previous/Next song
2. Long Press – Seek
That works, but what got me was that I didn’t know when the end of the long press was so I never knew when to stop seeking. I tried to attach an action to the UIButton on the UIControlEventTouchCancel event, but that is not correct.
This is my setup code:
gestureSeekBackward = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(seekBackward:)]; gestureTapBackward = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(previousSong:)]; gestureTapBackward.numberOfTapsRequired = 1; [backwardButton addGestureRecognizer:gestureSeekBackward]; [backwardButton addGestureRecognizer:gestureTapBackward];
What I needed to do was check whether the state is ended for the seek gesture. Continue reading