1

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

  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...

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

4

2 回答 2

0

尝试这个:

-(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];
        });
    });
}
于 2013-05-14T13:17:34.643 回答
0

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

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

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

希望这可以帮助。

于 2013-05-14T13:41:26.207 回答