UIImageView上的动画循环之间的延迟

时间:2013-05-14 13:12:01

标签: ios objective-c uiimageview

我有一个名为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...

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

2 个答案:

答案 0 :(得分: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];
        });
    });
}

答案 1 :(得分:0)

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

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

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

希望这有帮助。