Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop animation at current image

I have an image that is animating, until you press the button that says "Stop". The code works and all, but the image returns to the first image in the array. How can i add a code to tell it to stop at the image it's currently at?

- (void)viewDidLoad {

    [super viewDidLoad];

    imageView.animationImages = [NSArray arrayWithObjects:
                             [UIImage imageNamed:@"a0001.png"],
                             [UIImage imageNamed:@"a0002.png"],
                             [UIImage imageNamed:@"a0003.png"],
                             [UIImage imageNamed:@"a0004.png"],
                             [UIImage imageNamed:@"a0005.png"], nil];

    imageView.animationDuration = 3.00;
    imageView.animationRepeatCount = 0;
    [imageView startAnimating];
    [self.view addSubview:imageView];   
}

- (IBAction)stopAni {       
    [imageView stopAnimating];      
}

Thanks


Thanks dean, hey I need you once again :p now I've been able to stop it where I want, can I make it continue the animation where it has stopped??

like image 237
awlcs Avatar asked Aug 02 '10 14:08

awlcs


1 Answers

Set the image property of the UIImageView to be the one you want to stop at

- (IBAction)stopAni {
    [imageView stopAnimating];
    [imageView setImage:[[imageView animationImages] objectAtIndex:currentFrame];
}

The current frame is just the animation duration divided by the amount of time that you have been animatin (you'll have to store the time that you started animating yourself!)

like image 150
deanWombourne Avatar answered Oct 03 '22 01:10

deanWombourne