【问题标题】:How to load and animate images from Images.xcassets folder using UIImage array in objective c如何使用目标 c 中的 UIImage 数组从 Images.xcassets 文件夹中加载和动画图像
【发布时间】:2021-12-19 04:21:23
【问题描述】:

我在 Images.xcassets 中有一个包含 24 张图像的文件夹。我想将这些图像添加到 UIImage 数组并尝试按顺序对这些图像进行动画处理。是否可以将 Images.xcassets 中的图像加载到数组中?还是使用 SVG 图像制作动画更好?

为了获得单张图片,我尝试了以下方法:

UIImage *image =  [UIImage imageNamed:@"FolderName"];

但我想这需要修改为 Image 数组。

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    我想这可能对你有帮助

    UIImageView *imageView = [UIImageView.alloc initWithFrame:self.view.bounds];
        [self.view addSubview:imageView];
        
    NSMutableArray *images = NSMutableArray.array;
    NSInteger imageCount = 24;
    NSString *imagePrefix = @"imageName_";
    for(int i = 0; i<=imageCount; i++){
        NSString *imageName = [NSString stringWithFormat:@"%@%d",imagePrefix, i];
        UIImage *image = [UIImage imageNamed:imageName];
        [images addObject:image];
    }
    imageView.animationImages = images;
    imageView.animationRepeatCount = 1;
    imageView.animationDuration = 3.0;
    [imageView startAnimating];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-04
      • 2014-06-27
      • 2014-11-14
      • 1970-01-01
      • 1970-01-01
      • 2016-03-18
      相关资源
      最近更新 更多