我在 viewDidAppear 中有一个动画,如下所示
-(void)viewDidAppear:(BOOL)animated
{
for (int i = 0; i < 100; i++) {
p = arc4random_uniform(320)%4+1; //global integer
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];
}];
}
}
它只是从屏幕顶部创建小方块并移动到底部。我还有一个 UIImageView,它由 x 轴上的加速度计控制。目标不是触摸动画对象。就像一个简单的赛车游戏。但是我不知道如何检测 imageView 和动画之间的碰撞?