Ios 如何检测UIImageView之间的冲突?
我正在构建一个游戏,我想检测UIImageViews之间的冲突,我将所有UIImageView添加到一个数组中,还有一个球的图像在屏幕上反弹。我无法检测我在arrayself.myViews中添加的UIImageView与我在故事板中添加的球的UIImageView之间的冲突。我想不出这个问题Ios 如何检测UIImageView之间的冲突?,ios,objective-c,Ios,Objective C,我正在构建一个游戏,我想检测UIImageViews之间的冲突,我将所有UIImageView添加到一个数组中,还有一个球的图像在屏幕上反弹。我无法检测我在arrayself.myViews中添加的UIImageView与我在故事板中添加的球的UIImageView之间的冲突。我想不出这个问题 - (void) performAnimation { int widht; int heigh; for (UIView * obj in self.myViews){ [obj remov
- (void) performAnimation {
int widht;
int heigh;
for (UIView * obj in self.myViews){
[obj removeFromSuperview];
}
[self.myViews addObject:self.Ball];
[self.view addSubview: self.Ball];
for (heigh = 30; heigh < 200; heigh = heigh + 40) {
for (widht = 35; widht < 300; widht = widht + 40) {
UIImageView *image0 =[[UIImageView alloc] initWithFrame:CGRectMake(widht,heigh,20,10)];
image0.image=[UIImage imageNamed:@"gruener-balken.png"];
[self.view addSubview:image0];
[self.myViews addObject:image0];
}
}
}
- (void)BallMovement {
for (UIImageView *obj in self.myViews) {
if (CGRectIntersectsRect(obj.frame, _Ball.frame)) {
//something happens here
}
}
}
我想动态创建UIImageView,并将它们添加到可变数组myViews中。然后我想检测数组中的UIImageView和我在storyboard _Ball.frame中创建的ImageView之间的冲突。问题是,没有检测到碰撞,球从循环中移到图像视图的后面。并且您已检查代码是否被调用?并记录了帧?检测代码在哪里?Cocoa应用程序没有每帧都运行的tick方法,因此您需要在计时器驱动的方法中运行它……苹果在iOS 7中引入了UICollisionBehavior。看看这个目录,第二个循环被调用,但是if语句的断点没有效果。但是我不知道为什么。我也不知道为什么需要self.myview,因为你可以列举self.view的子视图。另外,在靠近顶部的子视图中移除的代码不会从self.myview中移除视图,最后应该始终存在冲突,因为它会比较self.Ball和self.Ball。。。