如何将多个图像加载到 WKInterfaceImage

How to load multiple images to WKInterfaceImage

WKInterfaceImage 的 setImageData 文档说 "The data can be raw image data or an archived UIImage object. ...... The data object in this parameter may contain multiple images so that the image content can be animated."

谁能告诉我如何从多个图像构造 NSData 对象的代码片段,该对象可以加载到 WKInterfaceImage 对象中?

这是我能解释的最好的方法。

UIImage * img1 = [UIImage imageNamed:@"img1.png"];
UIImage * img2 = [UIImage imageNamed:@"img2.png"];

UIImage * img = [UIImage animatedImageWithImages:@[img1, img2] duration:0];

NSData * data = [NSKeyedArchiver archivedDataWithRootObject:img];


[self.wkInterfaceImage setImageData:data];
[self.wkInterfaceImage startAnimating];

但这不起作用!

不使用 setImageData,只使用 setImage 并直接传递图像。

self.wkInterfaceImage setImage:img];

此外,您还需要将动画图像的持续时间更改为大于 0 的值。