【问题标题】:Delay between animation cycle on a UIImageViewUIImageView 上的动画周期之间的延迟
【发布时间】:2013-05-14 13:12:00
【问题描述】:

我有一个名为 imgView 的 UIImageView,其中有一组图像,例如,

  imageArray objects: [UIImage imageNamed:@"test4.png"],
                    [UIImage imageNamed:@"test5.png"],
                    [UIImage imageNamed:@"test6.png"],
                    [UIImage imageNamed:@"test7.png"],
                    nil];

然后我在 imgView 动画中添加了数组图像,比如

imgView.animationImages = imageArray;
imgView.animationRepeatCount = 0;
imgView.animationDuration = 2.0f;

[imgView startAnimating]; 

这里一切正常。一个动画周期结束后,我必须延迟 5 秒。怎么办,我用过

 [self performSelector:@select...

但不工作,请给我任何想法。

【问题讨论】:

    标签: ios objective-c uiimageview


    【解决方案1】:

    试试这个:

    -(void) viewWillAppear:(BOOL)animated {
        [super viewWillAppear:YES];
    
        [self animationMethod];  //where you start the animation
    }
    
    -(void) animationMethod {
        NSMutableArray *imageArray  = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:@"btnVideoEffectSample1.png"], [UIImage imageNamed:@"btnVideoEffectSample2.png"], [UIImage imageNamed:@"btnVideoEffectSample3.png"], [UIImage imageNamed:@"btnVideoEffectSample4.png"], nil];
        imgProfilePicture.animationImages = imageArray;
        imgProfilePicture.animationRepeatCount = 0;
        imgProfilePicture.animationDuration = 2.0f;
        [imgProfilePicture startAnimating];
        [imageArray release];
    
        double delayToStopAnimation = 2.0;
        dispatch_time_t startTime = dispatch_time(DISPATCH_TIME_NOW, delayToStopAnimation * NSEC_PER_SEC);
        dispatch_after(startTime, dispatch_get_main_queue(), ^(void){
            [imgProfilePicture stopAnimating];
    
            double delayToRestartAnimation = 5.0;
            dispatch_time_t startTime = dispatch_time(DISPATCH_TIME_NOW, delayToRestartAnimation * NSEC_PER_SEC);
            dispatch_after(startTime, dispatch_get_main_queue(), ^(void){
            [self animationMethod];
            });
        });
    }
    

    【讨论】:

    • animationMethod怎么办?
    • 你能详细解释一下吗?
    • 我需要把所有这些行都放上去吗? imgView.animationImages = imageArray; imgView.animationRepeatCount = 0; imgView.animationDuration = 2.0f; [imgView 开始动画];
    【解决方案2】:

    在 1 个循环完成后,使用 [imgView stopAnimating]; 并根据需要从超级视图中删除。在此之后放置一个 NSTimer,它将在 7 秒后调用并再次重新启动动画,因为整个图像周期需要 2 秒,总时间将为完成动画需要 2 秒。在此之后,您需要 5 秒的休息时间,那么总时间将是 7 秒。再次,您的方法将从 NStimer 方法调用开始动画 -

    [NSTimer timerWithTimeInterval:7.0 target:self selector:@selector(startAnimation) userInfo:nil repeats:YES];

    如果您有任何问题,请找到此链接here

    希望这会有所帮助。

    【讨论】:

    • 如何检测到一个周期已经完成?
    • 当您在 8 秒后开始制作动画时,您的循环将结束,因为每张图像需要 2 秒,而您有 4 张图像
    • 在 [imgView startAnimating] 之后;鉴于我如何检测到 8 秒已经完成..?
    • 重复计数后停止动画你可以看到它需要8秒
    • 如果你有问题可以在这里找到图片动画链接mobile.tutsplus.com/tutorials/iphone/uiimageview-animation
    猜你喜欢
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 2015-05-20
    • 2019-05-31
    相关资源
    最近更新 更多