我正在构建一个游戏,我想在其中检测UIImageViews之间的碰撞,我在阵列中添加所有UIImageViews,并且还有另一个球在屏幕上弹跳的图像。我无法检测到我在数组中添加的UIImageViews(self.myViews)与我在Storyboard中添加的球的UIImageView之间的碰撞。我无法弄清楚问题。
- (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
}
}
}
我想动态创建UIImageViews并将它们添加到一个可变数组(myViews)。然后我想检测数组中的那些UIImageViews和我在storyboard(_Ball.frame)中创建的ImageView之间的冲突。问题是,没有检测到碰撞,并且球从环路移动到图像视图后面。