Ios 如何检测UIImageView之间的冲突
我试着使用CGRectIos 如何检测UIImageView之间的冲突,ios,objective-c,xcode,Ios,Objective C,Xcode,我试着使用CGRect 但由于某些原因,它无法工作很抱歉,代码有点奇怪。您可以尝试使用CGRectContainsPoint,但您的实现中没有任何错误,可能是值不匹配。您确定它们都在同一坐标系中吗?也就是说,它们具有相同的超级视图?它们的帧取决于它们的超视图。 - (void)placeLine{ randomTop = arc4random()%300; randomTop = randomTop - 150; randomBot = randomTop + 300;
但由于某些原因,它无法工作很抱歉,代码有点奇怪。您可以尝试使用CGRectContainsPoint,但您的实现中没有任何错误,可能是值不匹配。您确定它们都在同一坐标系中吗?也就是说,它们具有相同的超级视图?它们的帧取决于它们的超视图。
- (void)placeLine{
randomTop = arc4random()%300;
randomTop = randomTop - 150;
randomBot = randomTop + 300;
line1.center = CGPointMake(randomTop, 000);
line2.center = CGPointMake(randomBot, 000);
if (CGRectIntersectsRect(ball.frame, line1.frame)){
[self gameOver];
}
if (CGRectIntersectsRect(ball.frame, line2.frame)){
[self gameOver];
}
}
- (void)gameOver {
self.view.backgroundColor = [UIColor blackColor];
}