как остановить анимацию на последнем кадре? - PullRequest
0 голосов
/ 14 апреля 2011

Как я могу остановить анимацию на последнем кадре. Код здесь: - (void)method{</p> <pre><code>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 scheduledTimerWithTimeInterval: 0.5f target: self selector: @selector(tick) userInfo: nil repeats: YES];

[self.view addSubview: somePicture];

}

- (Недействительными) клещ {

if(![somePicture isAnimating]) { [timer invalidate]; [somePicture stopAnimating]; timer=nil; NSLog(@"@ye1111eah!!!");}
else
NSLog(@"@y");}

Я знаю, что должен использовать NSTimer, но не знаю как: (

1 Ответ

0 голосов
/ 14 апреля 2011

Почему вы выделяете somePicture дважды

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 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"8Ball_003_00075.png"]];
somePicture.frame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);

ОБНОВЛЕНИЕ

Iдумаю, что это сделает это

    - (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");
}

надеюсь, что это поможет

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...