Renaissance
Renaissance

Reputation: 554

CGRectContainsRect giving wrong value

I have two rectangles which are defined as follows.

CGRect rect1  = CGRectMake(64.000000,1100.500000,704.000000,1971.500000);
CGRect rect2  = CGRectMake(88.000000,1757.416626,100.000000,1780.416626);

Now i know that rect2 is contained in rect1 , we can see that from points and it's obvious that CGRectContainsRect should give TRUE value. But when i log that value, it is FALSE.

if(CGRectContainsRect(rect1, rect2)){
   printf("yes1\n");
}else{
   printf("No1\n");
}

Upper code is giving false. Can anybody help me with this.

Upvotes: 0

Views: 643

Answers (1)

Lorenzo Linarducci
Lorenzo Linarducci

Reputation: 541

CGRectContainsRect will only return true when one rect is completely contained within the bounds of the second. In your example, the height of rect2 overlaps rect1.

You are looking for CGRectIntersectsRect.

Upvotes: 2

Related Questions