I couldn't find neither a property in the documentation, nor a suspicious ivar or private method after class-dumping UIKit, so the best I could think of is:
NSDate *startDate; // instance variable
- (void)startAnimation
{
startDate = [NSDate date];
[imageView startAnimating];
}
- (int)currentImageIndex
{
NSTimeInterval elapsed = -1 * [startDate timeIntervalSinceNow];
int nFrames = imageView.animationImages.count;
NSTimeInterval frameDuration = imageView.animationDuration / nFrames;
int current = elapsed / frameDuration;
return current % nFrames;
}
As to how to start the animation at a particular image: use an NSMutableArray
for storing the images, and rotate the array so that its first element is the image you want to begin with, then re-set the animationImages
property of the image view. To rotate an NSMutableArray
, see the answers to this question.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…