2 guodeganggdg guodegangGDG 于 2013.04.19 10:57 提问

怎么判断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个回答

love_loveec
love_loveec   2013.04.19 11:27

想要判断动画结束可能会引起很多其他麻烦。不过你可以试试这样的方法:

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
    }
}

只是举个例子,如果你的动画周期比timer短,可以用timer里进行isAnimating检测

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!