Question

I possède 6 UIImageViews reliés chacun à UIPanGestureRecognizer et ils sont tous reliés à la même méthode. La méthode est la suivante:

- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer {

CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, 
                                     recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}

Je suivais le tutoriel de Ray Wenderlich sur l'utilisation GestureRecognizers. Alors, je me demandais comment détecter les collisions de sorte que lorsque une image entre en collision avec une autre image, un code est exécuté. Le code est différent pour chaque image.

Merci

Était-ce utile?

La solution

If you want move the image with the recognizer maybe you should attach the recognizer to your view.

Belonging to this, the fastest way to do this, is (in the method that change the frame at your UIImageView)

for (UIImageView *iv in _imageArray){
   if (CGRectIntersectsRect(iv.frame, _selectedImageView.frame)) {
      NSLog(@"Collision");
   }
}

_selectedImageView is the image that your are moving and _imageArray is an array that contains all your UIImageView (in your case are 6).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top