使用CA在iphone中为多个图像设置动画

时间:2012-02-20 11:46:58

标签: iphone core-animation

我有一个UIViewController,其中包含16个UIImageView,现在我必须用Core Animation制作4个图像

知道怎么做吗?

我能够为我的代码设置动画

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position"];
anim.fromValue  = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
anim.toValue    = [NSValue valueWithCGPoint:CGPointMake(200, 200)];
anim.duration   = 1.5f;
anim.repeatCount =1;
anim.removedOnCompletion = YES;
anim.autoreverses = YES;
anim.repeatCount = 10;
anim.timingFunction = [CAMediaTimingFunction        
functionWithName:kCAMediaTimingFunctionEaseIn];
[imgview.layer  addAnimation:anim forKey:@"position"];

2 个答案:

答案 0 :(得分:0)

这是我脑海中的理论解决方案,在从(1到[yourImageArray count])的循环中,动态加载imageView,使用该循环中的索引从yourImage数组加载单个图像。使用imageView上的代码执行一些动画。

答案 1 :(得分:0)

UIImageViews是UIView的子类,它有以下方法:

animateWithDuration:delay:options:animations:completion

您可以通过以下方式使用它:

[UIView animateWithDuration:1.5f
                          delay:0.0f
                        options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
                     animations:^{
[UIView setAnimationRepeatCount:10];
[imgview1 setCenter:CGPointMake(200,200)];
[imgview2 setCenter:CGPointMake(300,200)];
[imgview3 setCenter:CGPointMake(400,200)];
[imgview4 setCenter:CGPointMake(500,200)];
};
                     completion:nil];