iPhone: detect any point in a rect in another rect
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开发者_Go百科 sometimes only parts of them will be on the screen but I still need to have them loaded into memory.
Use:
CGRectIntersectsRect(CGRect rect1, CGRect rect2)
you can use your rect's and the view's frame as the two parameters.
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.
精彩评论