【问题标题】:How can i tell when a simple png animation in iOS is finished?如何判断 iOS 中的简单 png 动画何时完成?
【发布时间】:2013-04-18 23:11:57
【问题描述】:

这是经典动画,但我需要知道它何时真正完成。谢谢

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];

【问题讨论】:

    标签: iphone ios ipad uiimageview


    【解决方案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 设置动画...

    【讨论】:

    • 谢谢。跳入 OpneGL 进行我的下一个动画。这肯定是一个聪明的技巧。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    相关资源
    最近更新 更多