2013-03-10 1 views
1

Je suis un débutant dans la programmation IOS ... Je ne suis pas familier avec les méthodes en ce moment. Le paramètre est: J'ai une fonction appelée. Dans cette fonction, je voudrais attendre un tap, puis générer un nouveau ViewController. J'ai seulement besoin du CGPoint de robinet puis passer aux étapes suivantes. Mais je ne sais pas s'il y a une méthode qui pourrait capturer les touches. Ou peut-être que je pense de la mauvaise façon. Quelqu'un pourrait-il m'en fournir?IOS, Xcode: capture événement UITouch terminé

Si je crée le nouveau viewController juste après la fin du contact, rien ne se passe après le modelDetect (c'est nécessaire). L'application se terminera avant d'avoir un contact.

Donc, je n'ai aucune idée maintenant.

Vraiment merci beaucoup.

- (void)modelDetect 
{ 
//wait for touches....then 
[self addNewViewController]; 
} 


- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    NSLog(@"touch happens"); 
    UITouch *touch = [touches anyObject]; 
    Location = [touch locationInView:self.view];  
} 

Répondre

2

Vous pouvez essayer d'utiliser UITapGestureRecognizer pourrait résoudre votre problème

UITapGestureRecognizer *rec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(userTapped:)]; 
[self addGestureRecognizer:rec]; 


- (void)userTapped:(UITapGestureRecognizer *)recognizer 
{ 
    if(recognizer.state == UIGestureRecognizerStateRecognized) 
    { 
     CGPoint point = [recognizer locationInView:recognizer.view]; 
     // point.x and point.y touch coordinates 
     NSLog("%lf %lf", point.x, point.y); 

     // here you could call your method or add the new view controller which you want 
     [self addNewViewController]; 
    } 
} 

Pour obtenir le point par touchesEnded vous devez utiliser CGPoint

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *aTouch = [touches anyObject]; 
    CGPoint point = [aTouch locationInView:self]; 
    // point.x and point.y touch coordinates 
    NSLog("%lf %lf", point.x, point.y); 
} 
+0

Merci you.I déjà résolu mes problèmes. – user2152814

Questions connexes