简体   繁体   中英

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?

Update (Solution so far): I was able to look into UIImage Animations and here's my current solution

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. 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.

The UIImageView class has built-in frame based animations. 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. It's well documented in the Xcode docs in the Animating Images section of the UIImageView class reference.

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.

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. Have a look at the documentation here: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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