ho ricevuto da Two action methods for an UIButton; next track and seek forward:
cambiare come il vostro requisito.
Personalmente mi limito a tenere traccia dello stato del pulsante con un numero intero sul controller di visualizzazione o all'interno di una sottoclasse di pulsanti. Se si tiene traccia di ciò che sta facendo il pulsante, è possibile controllare cosa fanno ciascuna azione. Nel file .h mettere in qualche cose come questa:
enum {
MyButtonScanning,
MyButtonStalling,
MyButtonIdle
};
@interface YourClass : UIViewController {
NSInteger buttonModeAt;
}
@property (nonatomic) NSInteger buttonModeAt;
-(IBAction)buttonPushedDown:(id)sender;
-(void)tryScanForward:(id)sender;
-(IBAction)buttonReleasedOutside:(id)sender;
-(IBAction)buttonReleasedInside:(id)sender;
@end
E poi nel file .m tiro in alcune di queste cose:
@implementation YourClass
///in your .m file
@synthesize buttonModeAt;
///link this to your button's touch down
-(IBAction)buttonPushedDown:(id)sender {
buttonModeAt = MyButtonStalling;
[self performSelector:@selector(tryScanForward:) withObject:nil afterDelay:1.0];
}
-(void)tryScanForward:(id)sender {
if (buttonModeAt == MyButtonStalling) {
///the button was not released so let's start scanning
buttonModeAt = MyButtonScanning;
////your actual scanning code or a call to it can go here
[self startScanForward];
}
}
////you will link this to the button's touch up outside
-(IBAction)buttonReleasedOutside:(id)sender {
if (buttonModeAt == MyButtonScanning) {
///they released the button and stopped scanning forward
[self stopScanForward];
} else if (buttonModeAt == MyButtonStalling) {
///they released the button before the delay period finished
///but it was outside, so we do nothing
}
self.buttonModeAt = MyButtonIdle;
}
////you will link this to the button's touch up inside
-(IBAction)buttonReleasedInside:(id)sender {
if (buttonModeAt == MyButtonScanning) {
///they released the button and stopped scanning forward
[self stopScanForward];
} else if (buttonModeAt == MyButtonStalling) {
///they released the button before the delay period finished so we skip forward
[self skipForward];
}
self.buttonModeAt = MyButtonIdle;
}
Dopo di che basta collegare le azioni del pulsante per quello che ho Ho notato nei commenti prima delle IBactions. Non ho provato questo, ma dovrebbe funzionare.
Solo una supposizione, fare un BOOL e il check-in sia il metodo e capovolgere l'azione: '- (void) removeTarget: action: ' –
Vuoi anche il contrario, ovvero se touchDown è attivato devi trascinare il cursore per non accadere se l'utente inizia a trascinare? L'unico modo per farlo funzionare sarà con un leggero ritardo all'inizio per vedere se inizia un trascinamento. Se questo non è accettabile, allora devi andare con un design diverso. – rdelmar