以下のコードは、画面の上から小さな正方形を作成し、下に移動するだけです。x軸の加速度計によって制御される UIImageView(player) もあります。エイムはアニメーション オブジェクトに触れていません。単純なレースゲームのように。エラーはありませんが、衝突を検出できません。コードに間違いが見つかりませんでした。何が問題になる可能性がありますか?
-(void)printOut:(NSTimer*)timer1;
{
for (int i = 0; i < 100; i++) {
p = arc4random_uniform(320)%4+1;
CGRect startFrame = CGRectMake(p*50, -50, 50, 50);
CGRect endFrame = CGRectMake(p*50, CGRectGetHeight(self.view.bounds) + 50,
50,
50);
animatedView = [[UIView alloc] initWithFrame:startFrame];
animatedView.backgroundColor = [UIColor redColor];
[self.view addSubview:animatedView];
[UIView animateWithDuration:2.f
delay:i * 0.5f
options:UIViewAnimationCurveLinear
animations:^{animatedView.frame = endFrame;}
completion:^(BOOL finished) {[animatedView removeFromSuperview];}];
CGRect movingFrame = [[animatedView.layer presentationLayer] frame];
if(CGRectIntersectsRect(player.frame, movingFrame)){
[timer invalidate];
NSLog(@"asdad");
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"You Lost" message:[NSString stringWithFormat:@"You were hit!"] delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
}
}
[timer1 invalidate];
}