how to stop the animation at the last frame?
How I can stop animation on the last frame.
Code here:
- (void)method{
NSMutableArray *images = [[NSMutableArray alloc]init];
NSInteger i;
for (i = 0; i < 75; i++){
NSString *str = [NSString stringWithFormat:@"pictures%i.png", i];
UIImage *img =[UIImage imageNamed:str];
[images addObject:img];
}
// Begin the animation
somePicture = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"8Ball_003_00075.png"]];
//somePicture = [[[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)] autorelease];
//[somePicture isAnimating]==0;
somePicture.frame = CGRectMake(0, 0, 320, 480);
[somePicture setAnimationImages:images];
somePicture.animationDuration = 5.0f;
somePicture.animationRepeatCount = 1;
[somePicture startAnimating];
somePicture.center = CGPointMake(160.0f, 230.0f);
//[images release];
[NSTimer scheduledTimerWithT开发者_Go百科imeInterval: 0.5f target: self selector: @selector(tick) userInfo: nil repeats: YES];
[self.view addSubview:somePicture];
}
-(void)tick{
if(![somePicture isAnimating]) { [timer invalidate]; [somePicture stopAnimating]; timer=nil; NSLog(@"@ye1111eah!!!");}
else
NSLog(@"@y");}
I know that I must used NSTimer but i don't know how :(
Why do you allocate somePicture
twice
somePicture = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"8Ball_003_00075.png"]];
somePicture = [[[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)] autorelease];
Can't you just use this
somePicture = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"8Ball_003_00075.png"]];
somePicture.frame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
UPDATE
I think this will do it
- (void)method{
NSMutableArray *images = [[NSMutableArray alloc]init];
NSInteger i;
for (i = 0; i < 75; i++){
NSString *str = [NSString stringWithFormat:@"pictures%i.png", i];
UIImage *img =[UIImage imageNamed:str];
[images addObject:img];
}
// Begin the animation
somePicture = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"8Ball_003_00075.png"]];
somePicture.frame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
self.view addSubview:somePicture];
//[somePicture isAnimating]==0;
[somePicture setAnimationImages:images];
somePicture.animationDuration = 5.0f;
somePicture.animationRepeatCount = 1;
somePicture.center = CGPointMake(160.0f, 230.0f);
[somePicture startAnimating];
[self performSelector:@selector(tick) withObject:self afterDelay:5.0];
}
- (void)tick
{
[somePicture stopAnimating];
if(![somePicture isAnimating])
{
NSLog(@"@ye1111eah!!!");
}
else
NSLog(@"@y");
}
hope this helps
精彩评论