尝试一次执行多个动画 [英] Trying to perform multiple animations at once
问题描述
我在网上找不到任何答案似乎很奇怪,但似乎如果你想以不同的速度同时移动 6 个 UIViews
,你做不到
Seems strange that i could not find any answer for this all over the net, but seems that if you want to move 6 UIViews
at the same time in a different speed ,you can't do that.
如果我使用这两个示例中的一个,我会发现有时只有一些视图在移动,有时所有视图都在移动(如预期).
If i am using one of this 2 example, i get that sometimes only some of the views are moving, and sometimes all of them (as expected) .
有没有办法同时移动6-7-8个UIViews,不同的持续时间?
There is no way to move 6-7-8 UIViews at the same time ,with different duration?
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];
}
推荐答案
你需要限制随机数生成器.
You need to limit the random number generator.
你的功能...
arc4random() % 10;
有时会返回 0.
然后将其传递给...
float time = 0.5 + 1/random;
将使 time = inf
.
您可以通过注销时间值来查看这一点.
You can see this by logging out the time values.
一段时间的 inf 会使按钮没有动画.
A time of inf will make the button not animate.
这篇关于尝试一次执行多个动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!