views:

81

answers:

2

Is there any way to detect if any point in a given rect is contained inside of another, larger, rect? I'm trying to figure out when certain rects are on the screen (for memory management to deallocate the ones that aren't) but the rects are large and so sometimes only parts of them will be on the screen but I still need to have them loaded into memory.

+1  A: 

You can use -pointInside:withEvent: which is a method for UIViews.

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event

Returns a Boolean value indicating whether the receiver contains the specified point.

See Apple's documentation here.

Brock Woolf
But he is looking for intersection between two rects. Using pointInside, he'll have to check if every point in one rect is a pointInside the other rect.
lukya
@lukya: Oops misread the question
Brock Woolf
+3  A: 

Use:

  CGRectIntersectsRect(CGRect rect1, CGRect rect2)

you can use your rect's and the view's frame as the two parameters.

lukya
Thanks so much, this is exactly what I needed!
Alexander
Better answer @Lukya +1
Brock Woolf