1

I have an UIImageView called imgView, where i have an array of images, like,

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

then i have added the array images in imgView animation, like

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

[imgView startAnimating]; 

Here every thing works fine. I have to delay 5sec after one cycle of animation finishes. How can i do this, i have used

 [self performSelector:@select...

but not working, please give me any idea.

Harish
  • 2,496
  • 4
  • 24
  • 48

2 Answers2

0

try this:

-(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];
        });
    });
}
DharaParekh
  • 1,730
  • 1
  • 10
  • 17
0

After 1 cycle complete use [imgView stopAnimating];and remove from super view if want.After this put an NSTimer which will be called after 7 sec and again restart your animation because whole image cycle takes 2 sec and total time will be taken 2 sec to complete animation. After this you want 5 sec break then total time will be 7 sec.Again your method will start animation from NStimer method calling like-

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

If you have any problem please find this link here

Hope this helps.

Community
  • 1
  • 1
iEinstein
  • 2,100
  • 1
  • 21
  • 32