WatchKit:如何在 objC 中动态地为存储在 Nsmutablearray 中的图像设置动画

WatchKit: How to animate Images stored in Nsmutablearray dynamically in objC

这里是我的疑问!!!

如何直接从 nsmutablearray 运行 gif 图像,我通过将其分配给 Wkinterfaceimage 来动态存储图像 ???

目前我正在处理分配给 wkinterfaceimage 的 GIf 图像。 我通过转换 gif 图像在 运行 时间内将一组图像存储在 Mutablearray 中。如何将该数组分配给 wkinterfaceimage 以显示 运行 gif 图像。 我在 swift 中发现了几个试图在 OBJ C 中实现的教程,请让我知道你在 Objective C

中的想法和代码

这是我的代码

 [imageView setImage:[frames objectAtIndex:0]];

 [imageView startAnimatingWithImagesInRange:NSMakeRange(0,frames.count) duration:1 repeatCount:0];

使用上面的代码在模拟器上显示空白屏幕,如果注释第二行显示 0 索引图像。

帧率结果

 2015-04-08 10:21:53.206 WatchkitDemo WatchKit Extension[852:24553] {
     DelayTime = "0.1";
     UnclampedDelayTime = 0; }

帧数组的结果

2015-04-08 10:21:58.807 WatchkitDemo WatchKit Extension[852:24553] (
    "<UIImage: 0x7fe358d2d320>",
    "<UIImage: 0x7fe358f05d60>",
    "<UIImage: 0x7fe358f08230>",
    "<UIImage: 0x7fe358d2fd50>"
)

有一种方法可以将从服务器接收到的 gif 图像转换为数组。我认为 Mayoff's UIImage Category 可以帮助你。我可以给你一个关于你可以做什么的想法:

1) 使用类别中定义的 任一 方法接收 gif

+[UIImage animatedImageWithAnimatedGIFData:(NSData *)data]
+[UIImage animatedImageWithAnimatedGIFURL:(NSURL *)url]

2) 进入实现文件UIImage+animatedGIF.m。在 line#89,方法 animatedImageWithAnimatedGIFImageSource 已实施。那里调用了方法 createImagesAndDelays 来创建图像数组。它将分离的图像存储在声明为 CGImageRef images[count].

的变量中

您可以使这个变量成为一个实例变量,或者使静态方法return成为一个分割的 gif 图像数组。

3) 将这些图像转换为 Wkinterfaceimage 接受的格式。

希望对您有所帮助:)