Question

Comment pourrais-je suivre un événement comme contact sur l'écran iPhone pendant 2 secondes. Comme dans Safari pour enregistrer l'image pour l'image ajoutée à un UIWebView?

Était-ce utile?

La solution

Créer un NSTimer avec +scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: dans la méthode de -touchesBegan:withEvent: de votre point de vue, et d'annuler (à l'aide -invalidate) dans -touchesEnded:withEvent:. Si la méthode de ses points de sélection est appelé à, l'utilisateur a tenu son doigt sur la vue pour quelque durée que ce que vous définissez l'intervalle de la minuterie. Exemple:

Interface (.h):

@interface MyView : UIView
    ...
    NSTimer *holdTimer;
@end

Mise en œuvre (.m):

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)evt
{
    [holdTimer invalidate];
    holdTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(touchWasHeld) userInfo:nil repeats:NO];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)evt
{
    [holdTimer invalidate];
    holdTimer = nil;
}

- (void)touchWasHeld
{
    holdTimer = nil;
    // do your "held" behavior here
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top