CGRectIntersectsRect Problem

时光总嘲笑我的痴心妄想 提交于 2019-11-28 11:49:46

问题


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
}


   }

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?

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


回答1:


try this one

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


来源:https://stackoverflow.com/questions/6696393/cgrectintersectsrect-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!