试图一次执行多个animation

似乎很奇怪,我无法在networking上find任何答案,但似乎如果你想以不同的速度同时移动6个UIViews ,你不能这样做。

如果我使用这个例子中的一个,那么我得到的结论是,有时候只有一部分视图正在移动,有时甚至全部移动(如预期的那样)。

无法同时移动6-7-8个UIViews, 持续 时间 不同

1。

 for(UIButton *button in buttons) { float r= arc4random()%10; float t =0.1+ 1.0/r; [UIView beginAnimations:@"Anim0" context:nil]; [UIView setAnimationDuration:t]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:button cache:YES]; CGRect newframe=button.frame; newframe.origin.y=0; button.frame=newframe; [UIView commitAnimations]; } 

2。

  for(UIButton *button in buttons) { int random=arc4random()%10; float time=0.5+ 1/(float)random; CGRect newframe=button.frame; newframe.origin.y=0; [UIView transitionWithView:button duration:time options:UIViewAnimationOptionCurveEaseInOut animations:^{ button.frame=newframe; } completion:nil]; } 

你需要限制随机数发生器。

你的function…

 arc4random() % 10; 

有时会返回0。

然后通过这个…

 float time = 0.5 + 1/random; 

将使time = inf

您可以通过注销时间值来查看。

inf的时间将使button不animation。

当然这是可能的。 问题是你发送错误的信息。 根据你的第二个片段,这是一个如何完成的例子:

 for (UIButton *button in self.buttons){ int random = arc4random()%10; float time = 0.5 + 1/(float)random; CGRect newframe = button.frame; newframe.origin.y = 0; [UIView animateWithDuration:time delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{ button.frame = newframe; } completion:^(BOOL finished) { // The animation have finished }]; }