开发者

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

开发者 https://www.devze.com 2023-02-22 10:59 出处:网络
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.

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 v开发者_Go百科iew not Image so CGRectIntersectsRect() won't give me the desired result. Is there any other way I can get the solution i.e. 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 ? i.e. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消