Hi, I have an array of images (about 100 320x240px 8k jpgs) that I run through using a timer. The first time the timer cycles through the images it goes very slowly--i'm guessing about 10fps. After that, it will play quickly (maybe up to 100fps).
First, what's going on here? I'm super curious. (some kind of memory or cpu throttling?) Second, I want the animation to run fast the first time. The only fix I've found is to run the animation once with the UIImageView offscreen. This takes a few seconds, however, which adds to the loading time. Is there a better way of "preloading" these images?
Here's my code. I'm on a 3g iphone with 3.0 sdk.
Code:
-(IBAction)startPressed:(id)sender{
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval: 0.01
target: self
selector:@selector(handleTimer:)
userInfo: nil
repeats: YES];
}
- (void) handleTimer: (NSTimer *) timer
{
static int i = 0;
if(i > imageArray.count - 1){
[timer invalidate];
i=0;
return;
}
finger.image = [imageArray objectAtIndex:i];
NSLog(@"%d", i);
i++;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
int i;
NSString *loadString;
imageArray = [[NSMutableArray alloc] init];
for(i = 1; i < 100; i++) {
loadString = [NSString stringWithFormat:@"finger %03d", i];
[imageArray addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:loadString ofType:@"jpg"]]];
NSLog(loadString);
}
finger.image = [imageArray objectAtIndex:0];
NSLog(@"Array Count: %d", [imageArray count]);
[super viewDidLoad];
}