CGRectIntersects矩形问题
我正在制作一个带有迷宫的应用程序,我在界面生成器中将一个球放在迷宫内(我为它放置了一个出口)我有一个 TouchMoved:
-(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 框架没有边界。那么为什么会发生这种情况呢?
我有另一个名为 flag 的 uiimageview iboutlet,我有相同的 cgrectintersectsrect 类型的代码,并且它在相同的 TouchMoved 中工作,那么为什么这不起作用
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
try this one