2014-02-12 104 views
0

我有两个图像的图像阵列,重复做一只鸟拍动翅膀。如何使图像阵列移动?

如何让阵列移动?

我有这样的数组:

NSArray *imageNames = @[@"bird1.png", @"bird2.png"]; 

NSMutableArray *birdflapping = [[NSMutableArray alloc] init]; 
for (int i = 0; i < imageNames.count; i++) { 
    [birdflapping addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]]; 
} 
UIImageView *animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 95, 86, 193)]; 
animationImageView.animationImages = birdflapping; 
animationImageView.animationDuration = 1; 

[self.view addSubview:animationImageView]; 
[animationImageView startAnimating]; 

我怎样才能使数组(作为一个整体)移动?

+0

什么意思为数组动?从数组中删除或动画移动? – simalone

回答

0
NSArray *animationArray=[NSArray arrayWithObjects: 
             [UIImage imageNamed:@"images.jpg"], 
              [UIImage imageNamed:@"images1.jpg"], 
              [UIImage imageNamed:@"images5.jpg"], 
             [UIImage imageNamed:@"index3.jpg"], 
         nil]; 
    UIImageView *animationView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,320, 460)]; 
     animationView.backgroundColor=[UIColor purpleColor]; 
     animationView.animationImages=animationArray; 
     animationView.animationDuration=1.5; 
    animationView.animationRepeatCount=0; 
     [animationView startAnimating]; 
     [self.view addSubview:animationView];  
0

这是你要移动的动画形象,而形象被绘制并包含在图像视图。要移动图像,您可以移动图像视图。一种方法是调整视图center属性的位置。另一种可能性是使用更多的图像,动画中的每个帧都显示鸟向前移动了一点。

也就是说,有很多更好的方法来做你想做的事情。您应该使用SpriteKit或Cocos2D来查看精灵动画。

+0

好的,谢谢,我想我会研究Cocos2D,我听说过很多。 – user3299835

0

你可以试试这个方法

UIImageView * animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200,200)]; 

NSArray *imageNames = @[@"bird1.png", @"bird2.png"]; 
animTime =.0; 
[animatedImageView setAnimationImages:imageNames] ; 
animatedImageView.animationDuration = animTime; 
animatedImageView.animationRepeatCount = 1; 
[self.view addSubview: animatedImageView]; 
[animatedImageView startAnimating]; 
+0

我想制作一个像效果一样的飞扬的鸟,鸟的翅膀瓣,如果用户触摸屏幕,它会向下移动,你知道该怎么做吗? – user3299835

0

你可以申请一个CGAffineTransformMakeTranslation如果你想要的是在屏幕上进行简单的移动整个鸟在一条线上。

喜欢的东西:

[UIView animateWithDuration:1.0 animations:^{ 
    // move bird as a whole, 300 units across the screen 
    self.animationImageView.transform = CGAffineTransformMakeTranslation(300,0); 
}];