0

Im using this code to try to detect collisions between two images, one of which is in an animation, but it doesn't work.

[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");
    }
}

How can i detect the collision?

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
Sarabyte Studios
  • 1,336
  • 2
  • 13
  • 16

1 Answers1

0

You can't use the frame of a view while it's being animated, the returned value will not be accurate. Instead, you should be able to get the presentationLayer from the views layer and check its frame.

Wain
  • 118,658
  • 15
  • 128
  • 151