Q:

CGRectContainsRect sometimes Not wotking

I'm having problems with this method. I add three view in storyboard.just like following:

Then I wirte some code:
if (CGRectContainsRect(self.redView.frame,self.blueView.frame)) { 
    NSLog(@"redView contain blueView!"); 
} else {
    NSLog(@"redView not contain blueView!");        
}

if (CGRectContainsRect(self.redView.frame,self.yellowView.frame)) {
    NSLog(@"redView contain yellowView!"); 
} else {
    NSLog(@"redView not contain yellowView!");    
}

NSLog(@"%@ %@ %@",NSStringFromCGRect(self.redView.frame),NSStringFromCGRect(self.blueView.frame),NSStringFromCGRect(self.yellowView.frame));
 {{36, 74}, {240, 260}} {{8, 8}, {120, 120}} {{112, 135}, {120, 120}}

But the result is: redView does not contain blueView!  redView contains yellowView! 
I just want to know why redView doesn't contain blueView? 

A:

The coordinates in your example show that the blue frame is actually not included in the red frame.  This is probably because the views don't share the same superview.  It looks like the blue view is a subview of the red view. 
You have to make sure that...

the tested views are in the same superview. 
or you convert their frames to the same coordinate system before testing. 

How to convert rects:
CGRect yellowRect = [self.yellowView convertRect:self.yellowView.bounds
                                          toView:self.redView];
if (CGRectContainsRect(self.redView.bounds, yellowRect)) {
    ...

