奇怪的是,我在网上找不到任何答案,但似乎如果你想以不同的速度同时移动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];
}发布于 2014-05-28 12:51:53
你需要限制随机数发生器。
你的功能..。
arc4random() % 10;有时会返回0。
然后把这个传给..。
float time = 0.5 + 1/random;将成为time = inf。
您可以通过注销时间值来看到这一点。
一个时间的inf将使按钮不动。
发布于 2014-05-28 12:29:36
当然,这是可能的。问题是你传递的信息是错误的。基于您的第二个片段,这是一个如何完成该操作的示例:
for (UIButton *button in self.buttons) {
int random = (arc4random() % 10) + 1; // "+1" Added later in the answer, see Fogmeister's answer
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
}];
}https://stackoverflow.com/questions/23911304
复制相似问题