【问题标题】:WatchKit: How to animate Images stored in Nsmutablearray dynamically in objCWatchKit:如何在 objC 中动态地对存储在 Nsmutablearray 中的图像进行动画处理
【发布时间】:2015-04-08 05:01:14
【问题描述】:

这是我的疑问!!!

如何直接从 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>"
)

【问题讨论】:

    标签: ios watchkit apple-watch xcode-6.2 wkinterfaceimage


    【解决方案1】:

    有一种方法可以将从服务器接收到的 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]的变量中。

    您可以将此变量设为实例变量,或使静态方法返回一个分割后的 gif 图像数组。

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

    希望对你有帮助:)

    【讨论】:

    • 谢谢 Buddy @iAnum .. 我会处理这个问题并回复你 :)
    • Asome It :) 好用,谢谢@iAnum
    猜你喜欢
    • 2012-11-17
    • 1970-01-01
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多