I currently have a UIImageView which I can move/drag around the view.
How does on detect for the edge of the screen when the image moves and stop the image from being a
You can find the rectangle of the UIImageView
in the coordinates of your (outermost) view using
CGRect r = [iv convertRect:iv.bounds toView:self.view];
Then it's a matter of checking if r
goes out of bounds, e.g. like this:
CGRect i = CGRectIntersect(r,self.view.bounds);
if ( CGRectIsNull(i) )
{
NSLog(@"way out of bounds");
} else if ( !CGRectEqualToRect(i,r) ) {
NSLog(@"partly out of bounds");
} else {
NSLog(@"self.view envelopes imageview");
}
Of course, this should be put in your dragging code, with the NSLog()
statements replaced with appropriate handling (e.g. by only updating location in the last case, or by translating the rect back into view if needed)