0

我使用此代码尝试检测两个图像之间的碰撞,其中一个在动画中,但它不起作用。

[UIView animateWithDuration:5 animations:^{
        bird.center = CGPointMake(bird.center.x, 600);
        fallTimer = [NSTimer scheduledTimerWithTimeInterval:.001 target:self selector:@selector(check) userInfo:nil repeats:YES];
    }];

-(void)check {
    if (CGRectIntersectsRect(bird.frame, cat.frame)) {
        NSLog(@"YES");
    }
}

如何检测碰撞?

4

1 回答 1

0

动画时不能使用视图的框架,返回的值将不准确。相反,您应该能够presentationLayer从视图中获取layer并检查其框架。

于 2013-07-18T23:14:54.133 回答