【问题标题】:How to make an image array move?如何使图像阵列移动?
【发布时间】:2014-02-12 03:02:22
【问题描述】:

我有一个包含两个图像的图像数组,这些图像重复以使鸟扇动翅膀。

如何使阵列移动?

我有这个用于数组:

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

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

【问题讨论】:

  • 数组移动是什么意思?从数组或动画移动中删除?

标签: ios uiimage nsarray


【解决方案1】:

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

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

【讨论】:

  • 好的,谢谢,我想我会研究一下 Cocos2D,我听说过很多。
【解决方案2】:
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];       

【讨论】:

    【解决方案3】:

    你可以试试这个方法

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

    【讨论】:

    • 我想做一个像飞鸟一样的效果,鸟的翅膀拍打,如果用户触摸屏幕它会向下移动,你知道怎么做吗?
    【解决方案4】:

    如果您想要的只是简单地将整只鸟在屏幕上排成一行,您可以应用 CGAffineTransformMakeTranslation。

    类似:

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

    【讨论】:

      猜你喜欢
      • 2016-07-19
      • 2021-06-21
      • 2016-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多