iphone sdk:如何使用CoreAnimation在UIImageView中设置动画集?

时间:2012-04-18 06:14:57

标签: iphone

我在UIImageView中加载了一组图像。如何使用CoreAnimation为UIImageView中的图像设置动画? Plz给我建议

2 个答案:

答案 0 :(得分:3)

这是一个非常漂亮的代码,用于为剩余时间制作动画图像,如果您设置定时器以报警动画中的图像根据计时器的剩余秒我使用图像制作花

{

// ----------------- image Animation ------------------- //

-(void)imageAnimationMethod

   {

 imageAnimation=[[UIImageView alloc]initWithFrame:CGRectMake(20, 150, 135, 135)];


  [ self.view addSubview:imageAnimation];

 imageAnimation.animationImages=[NSArray arrayWithObjects:
                                [UIImage imageNamed:@"101.png"],
                                [UIImage imageNamed:@"102.png"],
                                [UIImage imageNamed:@"103.png"],
                                [UIImage imageNamed:@"104.png"],
                                [UIImage imageNamed:@"105.png"],
                                [UIImage imageNamed:@"106.png"],
                                [UIImage imageNamed:@"107.png"],
                                [UIImage imageNamed:@"108.png"],
                                [UIImage imageNamed:@"109.png"],
                                [UIImage imageNamed:@"110.png"],
                                [UIImage imageNamed:@"111.png"],
                                [UIImage imageNamed:@"112.png"],
                                [UIImage imageNamed:@"113.png"],
                                [UIImage imageNamed:@"114.png"],
                                [UIImage imageNamed:@"115.png"],
                                [UIImage imageNamed:@"116.png"],

                             nil];

// -----剩下的是计时器的第二个剩余部分--------- //

  int i=remaining*16/16;


  imageAnimation.animationDuration=i;

  imageAnimation.animationRepeatCount=0;



 }
 }

答案 1 :(得分:2)

如果您想在imageView中设置动画集,请使用以下代码

UIImageView* animatedImageView = [[UIImageView alloc]init];
animatedImageView.animationImages = [NSArray arrayWithObjects:    
                                     [UIImage imageNamed:@"1.gif"],
                                     [UIImage imageNamed:@"2.gif"],
                                     [UIImage imageNamed:@"3.gif"],
                                     [UIImage imageNamed:@"4.gif"], nil];
animatedImageView.animationDuration = 1.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[self.view addSubview: animatedImageView];