2013-04-18 49 views
0

这是经典动画,但我需要知道它何时实际完成。感谢如何判断iOS中的简单png动画何时完成?

UIImageView* campFireView = [[UIImageView alloc] initWithFrame:self.view.frame]; 
campFireView.frame = CGRectMake(255.0f,0.0f,512.0f,384.0f); 

campFireView.animationImages = [NSArray arrayWithObjects: 
    [UIImage imageNamed:@"wish_launch_up_low_00000.png"], 
    [UIImage imageNamed:@"wish_launch_up_low_00001.png"], 
    [UIImage imageNamed:@"wish_launch_up_low_00002.png"], 
    [UIImage imageNamed:@"wish_launch_up_low_00003.png"], 
    [UIImage imageNamed:@"wish_launch_up_low_00004.png"], 
    [UIImage imageNamed:@"wish_launch_up_low_00005.png"], 
    ,nil]; 


    campFireView.animationDuration = 0; 
    campFireView.animationRepeatCount = 1; 

    [campFireView startAnimating]; 

    [self.view addSubview:campFireView]; 

回答

1

这是痛苦的检测UIImageView的动画..但如果你不介意的话惹你可以做这样的事情..

UIImageView* campFireView = [[UIImageView alloc] initWithFrame:self.view.frame]; 
campFireView.frame = CGRectMake(255.0f,0.0f,512.0f,384.0f); 

campFireView.animationImages = [NSArray arrayWithObjects: 
    [UIImage imageNamed:@"wish_launch_up_low_00000.png"], 
    [UIImage imageNamed:@"wish_launch_up_low_00001.png"], 
    [UIImage imageNamed:@"wish_launch_up_low_00002.png"], 
    [UIImage imageNamed:@"wish_launch_up_low_00003.png"], 
    [UIImage imageNamed:@"wish_launch_up_low_00004.png"], 
    [UIImage imageNamed:@"wish_launch_up_low_00005.png"], 
    ,nil]; 


    campFireView.animationDuration = 4; // <--- I changed the duration.. 
    campFireView.animationRepeatCount = 1; 

    [campFireView startAnimating]; 

    [self.view addSubview:campFireView]; 

...

// detect it with timer 
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(onTimer) userInfo:nil repeats:YES]; 

-(void)OnTimer { 
    if ([campFireView isAnimating]) 
    { 
     // still animating 
    } 
    else 
    { 
     // Animating done 
    } 

} 

这只是一个例子,但如果你的动画持续时间少于定时器,你可以使用定时器来检查它以验证isAnimating ...

但是,有很多选项可以动画其他UIImageView ...

+0

谢谢。跳入OpneGL以获得我的下一个动画。这当然是一个聪明的黑客。 –

相关问题