title: How to keep a rotated UIView inside another UIView? (frame can't be used)
body: <p>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.</p>
  
  <p>I simplified the problem in this xcode project <a href="https://github.com/nextorlg/Intersection" rel="nofollow">https://github.com/nextorlg/Intersection</a>.</p>
  
  <p>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.</p>
  
  <p>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 <a href="https://github.com/nextorlg/Intersection/blob/master/intersec/MovableView.m" rel="nofollow">https://github.com/nextorlg/Intersection/blob/master/intersec/MovableView.m</a> )</p>
  
  <pre><code>-(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 &lt; INSET ||
           intersectionRect.size.height &lt; INSET ) {
           return NO;
      }
      else {
          return YES;
      }
  }
  </code></pre>
  
  <p>The question is, <strong>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?</strong></p>
  
  <p>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.</p>
  
  <p>I recommend you to download and run the project to understan better the problem, it is difficult to understand it just reading this.</p>
  
  <p>Thank you!</p>