CGRectIntersectsRect [英] CGRectIntersectsRect

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

问题描述

可能的重复:
CGRectIntersectsRect 问题

我正在制作一个带有迷宫的应用程序,我在界面构建器的迷宫内放了一个球(我为它放了一个出口)我有一个touchesMoved:

I am making a app with a maze, I put a ball inside the maze in the interface builder (I put an outlet for it) I have a touchesMoved:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint point;
    point = [touch locationInView:self.view];

    ball.center = point;

    if (CGRectIntersectsRect(ball.frame, maze.frame)) {
       //my stuff
    }
}

我有两个 CGRectIntersectsRect if 语句,我说,如果球的框架接触到迷宫的框架,那么//我的事情发生了,但是出于某种原因,每当我尝试移动球时,而不接触迷宫的框架,//我的事情发生了.我不知道为什么,也许是因为球在迷宫中,也许不是因为我说如果 cgrectintersectsrect 框架没有边界.那么为什么会发生这种情况?

I have two CGRectIntersectsRect if statements, I say, if the ball's frame touches the maze's frame, then // my stuff happens, but for some reason, whenever i try to move the ball, without touching the frame of the maze, // my stuff happens. I dont know why, maybe it is because the ball is IN the maze, probably not because i said if cgrectintersectsrect frame not bounds. so why is this happening?

推荐答案

CGRectIntersectsRect 将返回 true 如果 rect1 的任何部分位于 rect2 内.因此,当您的球完全在迷宫内时,您的交叉测试将始终为真.

CGRectIntersectsRect is going to return true if any part of rect1 lies inside of rect2. So while your ball is completely inside your maze, your intersection test will always be true.

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

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