UIButton - press and hold, press

I have several UIButtons that control the iPhone music player.

I would like the music player to search backward if the previous button was touched and held, but skip the previous item if the button was pressed.

Currently, I can navigate to the previous item with a tap, but touch and hold will seek back AND navigate to the previous item after clicking the button.

Here is the code I'm currently using:

- (void)previousButtonTouchedDown {
 [self performSelector:@selector(seekBackwards) withObject:nil afterDelay:1];
}

- (void)previousButtonTouchedUpInside { 
 MPMusicPlaybackState playbackState = self.iPodPlayer.playbackState;

 if (playbackState == MPMusicPlaybackStateSeekingBackward) {
  [self.iPodPlayer endSeeking];
 } else {
  [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(seekBackwards) object:nil];
  [self.iPodPlayer skipToPreviousItem];
 }
}

- (void)seekBackwards {
 [self.iPodPlayer beginSeekingBackward];
}

      

How can I search forward but not navigate to the previous item if the button is pressed, held, and then clicked?

Thank.

+2


source to share


2 answers


I haven't tested this and I don't know if this is the best solution.

  • You can attach an action to the UIControlEventTouchedDown button and then start the timer for about 1 second.
  • When the timer fires, it can call a method that starts looking.
  • Then add another method to the UIControlEventTouchedUp button.
    • Check if the player is looking for
      • if it searches, stop searching
      • else, skip ahead.


How does this sound?

0


source


Yes.

After running my app on a 3.1.2 OS device (using the same code from the original post), the problem seems to be fixed. The same code that looks for AND skips on device 3.0 ONLY looks for device 3.1.2.



So it seems that as of 3.0, the play state of the player on UIControlEventTouchedUp is equal to play, not skip. In 3.1.2, this is the opposite.

Does anyone know of a solution that doesn't include checking the playback status of the player?

0


source







All Articles