首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试一次执行多个动画

尝试一次执行多个动画
EN

Stack Overflow用户
提问于 2014-05-28 12:13:19
回答 2查看 178关注 0票数 0

奇怪的是,我在网上找不到任何答案,但似乎如果你想以不同的速度同时移动6 UIViews,你就不能这么做。

如果我使用这两个示例中的一个,我会发现有时只有一些视图在移动,有时所有视图都在移动(如预期的那样)。

没有办法同时移动6-7-8 UIViews ,使用不同的持续时间

1.

代码语言:javascript
复制
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.

代码语言:javascript
复制
 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];
    }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-05-28 12:51:53

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

你的功能..。

代码语言:javascript
复制
arc4random() % 10;

有时会返回0。

然后把这个传给..。

代码语言:javascript
复制
float time = 0.5 + 1/random;

将成为time = inf

您可以通过注销时间值来看到这一点。

一个时间的inf将使按钮不动。

票数 2
EN

Stack Overflow用户

发布于 2014-05-28 12:29:36

当然,这是可能的。问题是你传递的信息是错误的。基于您的第二个片段,这是一个如何完成该操作的示例:

代码语言:javascript
复制
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
                     }];
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23911304

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档