CGRectContainsRect不起作用 [英] CGRectContainsRect Not Working

查看:259
本文介绍了CGRectContainsRect不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这种方法的问题。我有两个明显相互包含的矩形。(我甚至手动绘制了它们的坐标以确保。)当我使用CGRectContainsRect来比较这两个矩形时,它返回false。对于我的生活,我已经尝试了一切,在网上搜索,我找不到这个问题的答案。任何人都知道为什么?我在调试时已经包含了CGRects的值,以表明它们肯定在彼此之内。

I'm having problems with this method. I have two rectangles that are obviously contained within each other.(I've even graphed their coordinates manually to make sure.) When I use CGRectContainsRect to compare these two rectangles, it returns false. For the life of me, I have tried everything, scoured the net, and I can't find an answer to this problem. Anyone have any idea why? I've included the values for the CGRects when I debug to show that they are definitely within each other.

-(bool)checkBoundingBox {
    bool returnItem = YES;

    //Checks for sprite interaction
    for (int i = 0; i < [arrGameItems count]; i++) {
        CGRect rect2 = [[self getChildByTag:1] boundingBox];
        CGRect rect1 = [[self getChildByTag:3] boundingBox];

        //        rect1 = CGRectStandardize(rect1);
        //        rect2 = CGRectStandardize(rect2);

        if (CGRectContainsRect(rect2, rect1)) {
            CCLOG(@"removed child b*&ch");
            [self removeChildByTag:[arrGameItems count] cleanup:YES];
            returnItem = NO;
        }
    }   

    CCLOG(@"g-dammit");    
    return returnItem;
}

rect1
原点x = 141 y = 76,身高= 25 ,width = 25

rect1 origin x = 141 y = 76, height = 25, width = 25

rect2
原点x = 127 y = 91,身高= 25,宽度= 25

rect2 origin x = 127 y = 91, height = 25, width = 25

推荐答案

CGRectContainsRect()检查一个矩形是否完全包含另一个矩形,而不仅仅是它们是否相交。从坐标开始,矩形不会相互包含,而只是相交。您正在寻找 CGRectIntersectsRect()

CGRectContainsRect() checks if one rectangle completely encompasses another, not just if they intersect. From your coordinates, the rectangles don't contain each other, but just intersect. You're looking for CGRectIntersectsRect().

这篇关于CGRectContainsRect不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆