CGRectIntersectsRect问题 [英] CGRectIntersectsRect Problem

查看:85
本文介绍了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?

我还有一个uiimageview的iboutlet,称为flag,我具有相同的cgrectintersectsrect类型的代码,并且在相同的touchesMoved下工作,所以为什么这样做不起作用

I have another iboutlet of a uiimageview called flag, i have the same cgrectintersectsrect type of code, and it works in the same touchesMoved, so why does this not work

推荐答案

尝试这个

UITouch *touch = [[event allTouches] anyObject];

CGPoint point;

point = [touch locationInView:self.view];


point = [[CCDirector sharedDirector] convertToGL: point];


if (CGRectIntersectsRect(ball.bounds, maze.bounds)) {


//frame - x,y,w,h

//bounds- w,h

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

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