Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to figure out if two CGRect intersect?

Tags:

iphone

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 say is:

If you have two sheets of paper on the desk, and one of them covers the other either completely or just a small portion, it is rectsIntersect = YES.

How to check that out for rect and anotherRect?

like image 496
dontWatchMyProfile Avatar asked Apr 26 '10 14:04

dontWatchMyProfile


1 Answers

Use bool CGRectIntersectsRect (CGRect rect1,CGRect rect2);

Swift 3:

public func intersects(_ rect2: CGRect) -> Bool 

Example: rect1.intersects(rect2)

like image 168
Matt Greer Avatar answered Oct 03 '22 01:10

Matt Greer