首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按顺序播放多个动画

按顺序播放多个动画
EN

Stack Overflow用户
提问于 2013-07-06 16:13:02
回答 2查看 480关注 0票数 0

我正在尝试执行球爆破效果,以发挥顺序。接二连三。

我做了什么:

我用过的球体爆破效果

代码语言:javascript
复制
UIButton *ballButton = (UIButton *)[cell viewWithTag:10];

ballButton.imageView.animationImages = [[NSArray alloc] initWithObjects:
                                        [UIImage imageNamed:@"1.png"],
                                        [UIImage imageNamed:@"2.png"],
                                        [UIImage imageNamed:@"3.png"],
                                        [UIImage imageNamed:@"4.png"],
                                        nil];
ballButton.imageView.animationDuration = 1;
ballButton.imageView.animationRepeatCount = 1;

代码上的这一行附加到集合视图单元格中的多个按钮。我把这些叫做ballbutton.imageview,像这样启动动画

代码语言:javascript
复制
[UIView animateWithDuration:1 delay:5 options:UIViewAnimationOptionCurveEaseOut animations:^{
        NSIndexPath *path2 = [NSIndexPath indexPathForRow:x inSection:0];
        UICollectionViewCell *cell = [ballContainer cellForItemAtIndexPath:path2];
        UIButton *ballObject = (UIButton *) [cell viewWithTag:10];
        [ballObject.imageView startAnimating];
    } completion:^(BOOL b){
          NSLog(@" here i call next animation of ball blast to execute ");
}];

我嵌套了3个像这样的动画按钮。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-07-11 04:22:03

这样我就解决了我的问题。最初,我通过调用以下命令来启动动画

代码语言:javascript
复制
        [self startAnim:index];

而不是像这样实现这个StartAnim并解决问题。

代码语言:javascript
复制
-(void)StartAnim :(int)x{

    NSIndexPath *path2 = [NSIndexPath indexPathForRow:x inSection:0];
    UICollectionViewCell *cell = [ballContainer cellForItemAtIndexPath:path2];
    UIButton *ballObject = (UIButton *) [cell viewWithTag:10];
    [ballObject setBackgroundImage:nil forState:UIControlStateNormal];
    ballObject.imageView.image = nil;
    [ballObject.imageView startAnimating];

    double delayInSeconds = 0.15;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

        if(x-6>=0){
            [self StartAnim :(x-6)];
        }
    });



}
票数 0
EN

Stack Overflow用户

发布于 2013-07-07 09:41:50

首先,你为什么不为其他三个人制作一个大动画呢?UIView animateWithDuration:的特点是,它在给它的时间内执行动画块,也就是说,将框架从(200,200)设置为(0,0)将在一秒钟内(在您的情况下)按比例移动。但是UIImageView关于动画的属性是以这样的方式制作的,即动画已经为您完成了。

就我个人而言,我建议使用计时器,就像这样:

代码语言:javascript
复制
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:ballObject.imageView.animationDuration
                                                  target:self 
                                                selector:@selector(performNextAnimation:) 
                                                userInfo:nil repeats:NO];
[ballObject.imageView startAnimating];

performNextAnimation方法中:

代码语言:javascript
复制
- (void) performNextAnimation{
[timer invalidate]; // you have to access the timer you've scheduled with the animation
timer = nil;
/* code for starting the next animation */
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17504712

复制
相关文章

相似问题

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