简体   繁体   English

IOS (Objective-C) 如何从 UIImages 数组无限期更改 UITableView 单元格中的图像

[英]IOS (Objective-C) How to indefinitely change the image in a UITableView Cell from an Array of UIImages

How can I make two images interchangeably animate indefinitely in a UITableViewCell?如何让两个图像在 UITableViewCell 中无限期地交替动画?

Update (Solution so far): I was able to look into UIImage Animations and here's my current solution更新(到目前为止的解决方案):我能够查看 UIImage Animations,这是我当前的解决方案

NSArray *imagesArray = [NSArray arrayWithObjects:imageA,imageB,nil];
UIImage *x=[UIImage animatedImageWithImages:imagesArray duration:2.0f];
cell.imageView.image=x;

Take a look at the NSTimer class.看看NSTimer类。 When you create the timer, you'll specify a target object, a selector, a time interval, and whether or not the timer repeats.创建计时器时,您将指定目标对象、选择器、时间间隔以及计时器是否重复。 Basically, you can have the timer send a message to the view controller in charge of your table every so often.基本上,您可以让计时器每隔一段时间向负责您的表的视图控制器发送一条消息。 When the view controller receives the message, that method should change the image in the table.当视图控制器收到消息时,该方法应该更改表中的图像。

The UIKit has everything ready-made for you. UIKit 为您准备好了一切。

The UIImageView class has built-in frame based animations. UIImageView 类具有内置的基于帧的动画。 You install an array of images in the image view's animationImages array, configure the timing of the animation, and then start it animating with a startAnimating call.您在图像视图的 animationImages 数组中安装一组图像,配置动画的时间,然后使用 startAnimating 调用启动动画。 It's well documented in the Xcode docs in the Animating Images section of the UIImageView class reference.它在 UIImageView 类参考的动画图像部分的 Xcode 文档中有详细记录。

You should create a custom subclass of UITableViewCell that has an image view in it and configure the image view to run a continuously repeating frame animation.您应该创建一个 UITableViewCell 的自定义子类,其中包含一个图像视图,并将图像视图配置为运行连续重复的帧动画。

Maybe I am not following what you want to do, but one simple solution would be to just use the properties animationImages and animationDuration on UIImageView in your cell.也许我没有遵循您想要做的事情,但一种简单的解决方案是在您的单元格中使用UIImageView上的属性animationImagesanimationDuration Have a look at the documentation here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImageView_Class/#//apple_ref/occ/instp/UIImageView/animationImages看看这里的文档: https : //developer.apple.com/library/ios/documentation/UIKit/Reference/UIImageView_Class/#//apple_ref/occ/instp/UIImageView/animationImages

You basically just provide an array of images and set the duration to an appropriate length so that each of your images displays for 2/3 of a second as requested.您基本上只需提供一组图像并将持续时间设置为适当的长度,以便您的每个图像按要求显示 2/3 秒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM