UIPanGestureRecognizer 碰撞
我有 6 个 UIImageView,每个都连接到 UIPanGestureRecognizer,并且它们都连接到相同的方法。方法是:
- (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];
}
我正在遵循 Ray Wenderlich 的关于使用 GestureRecognizers 的教程。所以,我想知道如何检测碰撞,以便当一个图像与另一图像碰撞时,运行一些代码。每个图像的代码都不同。
谢谢
I have 6 UIImageViews each connected to UIPanGestureRecognizer and they are all connected to the same method. The method is:
- (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];
}
I am following Ray Wenderlich's tutorial on using GestureRecognizers. So, I was wondering how to detect collisions so that when one image collides with another image, some code is run. The code is different for each image.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想使用识别器移动图像,也许您应该将识别器附加到您的视图中。
属于此,最快的方法是(在更改 UIImageView 的框架的方法中)
_selectedImageView
是您正在移动的图像,_imageArray
是包含所有 UIImageView 的数组(在您的例子中是 6)。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)
_selectedImageView
is the image that your are moving and_imageArray
is an array that contains all your UIImageView (in your case are 6).