Multiple UIView's overlapping
===

I am creating multiple custom `UIView's` in a custom `UIView`. The creation of the custom sub-views is ok. They look like this:

![enter image description here][1]


The draw method is quite straightforward: 

    [[UIColor brownColor] set];
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(ctx,
                          5.0f);
    CGContextBeginPath(ctx);
    CGContextMoveToPoint(ctx, 0.0f, 0.0f);
    CGContextAddLineToPoint(ctx, 100.0f, 0.0);
    CGContextAddLineToPoint(ctx, 130.0f, 25.0f);
    CGContextAddLineToPoint(ctx, 100.0f, 50.0f);
    CGContextAddLineToPoint(ctx, 0.0f, 50.0f);
    CGContextClosePath(ctx);
    CGContextStrokePath(ctx);
    [super drawRect:rect];

Adding it to the super view is also quite simple:


        ITContextFigure *view = [[ITContextFigure alloc] initWithFrame:CGRectMake(location.x, location.y, 135.0f, 50.0f)];
        [view setBackgroundColor:[UIColor yellowColor]];
        [self addSubview:view];

So my questions are:

**1) How can I detect when one overlaps the other?** 

I saw this solution:

    if (CGRectContainsRect([myImageView1 frame], [myImageView2 frame])) {
            NSLog(@"Overlaped, it's working!");
    }

But if I have multiple `UIViews`, doing a `for` on the `super view` and checking every single sub-view doesn't seem a good solution for me.

**2) In this case, what can be done?**

![enter image description here][2]


**My main goal** is to detect when this happens:

![enter image description here][3]


  [1]: http://i.stack.imgur.com/v2ogC.png
  [2]: http://i.stack.imgur.com/wRGV0.png
  [3]: http://i.stack.imgur.com/AotKw.png