简体   繁体   中英

How to detect Collision Between two UIImageViews belonging in two different UIViews?

I am noob in Iphone programming, so please help.

I am rotating 2 Views in opposite direction in circular way. Now I want to find out when both images are intersected.

As of now I am rotating view not Image so CGRectIntersectsRect() won't give me the desired result. Is there any other way I can get the solution ie intersection of both images ?

My problem is both are in different views. Any idea or suggestion or code snippet would be great to work further towards my goal.

--Edited-- I have 2 views in one view 1st image in another 2nd image. I am rotating both views in different direction circular. there will be one time when both image will be at same location. I am unable to use CGRectIntersectsRect() as both are in different views.

How do I know that both image met at location ? ie Collision occurred. Please forgive abt not providing clear explanation about question.

Try this method to convert the rect in the view to the rect in window coordinates, then use CGRectIntersectsRect() . Hope this works for you.

Converts a rectangle from the receiver's coordinate system to that of another view.

  • (CGRect)convertRect:(CGRect)rect toView:(UIView *)view

Parameters rect A rectangle in the receiver's coordinate system. view The view that is the target of the conversion operation. If view is nil, this method instead converts from window base coordinates. Otherwise, both view and the receiver must belong to the same UIWindow object. Return Value The converted rectangle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM