Reputation: 361
I am writing an application where there is a central UIImageView
and many other images are generated dynamically and move around the screen. I want to know when the central UIImageView
collides with ANY of the dynamically generated objects. I know there is the CGRectIntersectsRect
, but I have to specify the other object and this is not possible since there are many of them. Instead, I want to know when a collision happens with ANY object.
Upvotes: 0
Views: 408
Reputation: 5418
Please take a look at UIKit Dynamics. Here is the awesome Tutorial. Also Refer Apple Documentation
Upvotes: 0
Reputation: 20284
Since most of the elements are subclasses of UIView, you may be able to check for intersection with all elements using this code:
//imageView represents your central UIImageView
for (UIView *view in self.view.subviews)
{
if (CGRectIntersectsRect(imageView.frame, view.frame) && ![view isEqual: imageView])
{
//Implement relevant code here
}
}
Upvotes: 1