I want to have a movable/scalable/rotable view inside another view. The inner view can go outside the outer view's frame but I want to keep part of it inside the outer one so the inner view isn't lost.
I simplified the problem in this xcode project https://github.com/nextorlg/Intersection.
If the inner view was only movable and scalable the problem would be already solved but when the inner view rotates this solution it is not good because the frame contains the view but it is not the view itself.
Every transformation performed to the inner view I use this function to validate the new view position, if it is not valid I revert the last transformation ( this is the movable view code https://github.com/nextorlg/Intersection/blob/master/intersec/MovableView.m )
-(BOOL) validInset {
CGRect outerLimit = CGRectMake(0, 0, self.superview.frame.size.width, self.superview.frame.size.height);
CGRect intersectionRect = CGRectIntersection(self.frame, outerLimit);
NSLog(@"self.frame:%f,%f,%f,%f", self.frame.origin.x, self.frame.origin.y, self.frame.size.width, self.frame.size.height);
NSLog(@"outer.frame:%f,%f,%f,%f", outerLimit.origin.x, outerLimit.origin.y, outerLimit.size.width, outerLimit.size.height);
NSLog(@"intersec.frame:%f,%f,%f,%f", intersectionRect.origin.x, intersectionRect.origin.y, intersectionRect.size.width, intersectionRect.size.height);
NSLog(@"========================");
if ( CGRectIsNull(intersectionRect) ||
intersectionRect.size.width < INSET ||
intersectionRect.size.height < INSET ) {
return NO;
}
else {
return YES;
}
}
The question is, how can I be sure the inner view it is not lost behind the outer view when the first is rotated some (45 for example) degrees and dragged to a corner?
One comment, I want to keep just some pixels inside the outer view because the inner view can be bigger (scaled) than the outer one.
I recommend you to download and run the project to understan better the problem, it is difficult to understand it just reading this.
Thank you!