How to figure out if two CGRect intersect?

后端 未结 2 916
鱼传尺愫
鱼传尺愫 2021-01-01 10:01

In -drawRect: I want to check if the provided rect intersects with anotherRect.

I\'m not good at this geometry math stuff and especially at english so what I want to

2条回答
  •  旧时难觅i
    2021-01-01 10:41

    Try to use this.. While animating imageview you can get its actual frame by this:

    [[obstacle1.layer presentationLayer] frame];
    

    So, it will easily to make collision of two imageview

    if (CGRectIntersectsRect([[obstacle1.layer presentationLayer] frame], [[bgImageView.layer
        presentationLayer] frame])) 
    {
    
        NSLog(@"Collision 1");
    
    }
    

提交回复
热议问题